-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestscript.py
More file actions
34 lines (30 loc) · 834 Bytes
/
testscript.py
File metadata and controls
34 lines (30 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Squares(object):
def __init__(self, start, stop):
self.start = start
self.stop = stop
def __iter__(self):
return self
def next(self):
if self.start >= self.stop:
raise StopIteration
current = self.start * self.start
self.start += 1
return current
a = Squares(1, 100)
for b in a:
print b
class Singleton(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton,cls).__new__(cls,*args,**kwargs)
return cls._instance
import functools
def singleton(f):
instance = {}
functools.wraps(f)
def wrapper(*args, **kwargs):
if f not in instance:
instance[f] = f(*args, **kwargs)
return instance[f]
return wrapper()