-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.py
More file actions
81 lines (56 loc) · 1.69 KB
/
class.py
File metadata and controls
81 lines (56 loc) · 1.69 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class Screen(object):
@property
def width(self):
return self._width
@width.setter
def width(self, val):
self._width = val
@property
def height(self):
return self._height
@height.setter
def height(self, val):
self._height = val
@height.deleter
def height(self):
del self._height
@property
def resolution(self):
return self._height * self._width
class Student(object):
def __init__(self, name):
self.name = name
def __str__(self):
return 'Student Object (name:%s)' % self.name
# __repr__ = __str__
class Fib(object):
def __init__(self):
self.a, self.b = 0, 1 # 初始化两个计数器a,b
def __iter__(self):
return self # 实例本身就是迭代对象,故返回自己
def __next__(self):
self.a, self.b = self.b, self.a + self.b # 计算下一个值
if self.a > 100000: # 退出循环的条件
raise StopIteration();
return self.a # 返回下一个值
class Chain(object):
def __init__(self, path=''):
self._path = path
def __getattr__(self, path):
return Chain('%s/%s' % (self._path, path))
def __call__(self, user):
return Chain('%s/%s' %(self._path, user))
def __str__(self):
return self._path
__repr__ = __str__
print(Chain().status.user('fuck').timeline.list)
# print(s)
# test:
# s = Screen()
# s.width = 1024
# s.height = 768
# print(s.resolution)
# s.height
# print(s.resolution)
# assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution
# print(dir(s))