-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04_magic.py
More file actions
76 lines (42 loc) · 1.11 KB
/
04_magic.py
File metadata and controls
76 lines (42 loc) · 1.11 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Human(object):
def __init__(self, name=None):
super(Human, self).__setattr__('_dict', {})
self._dict['name'] = name
def __setattr__(self, name, value):
self._dict[name] = value
def __getattr__(self, name):
return self._dict.get(name, None)
def __delattr__(self, name):
try:
del self._dict[name]
except:
pass
def __eq__(self, obj):
print False
def __str__(self):
return self.name if self.name else 'Unnamed Human'
def __unicode__(self):
return self.name if self.name else u'Unnamed Human'
def __repr__(self):
return str(self._dict)
krishna = Human("Krishna")
ram = Human("Ram")
ram.is_married = True
ram.wife = "sita"
ram == krishna
print ram.wife
del ram.wife
print ram.wife
# print unicode(ram)
# print krishna
# print krishna.name
# print ram.name
# print krishna.email
# print ram.email
# print str(krishna)
# print unicode(krishna)
# print repr(krishna)