On Thu, Dec 29, 2011 at 9:07 AM, Prim wrote:
> class C:
> def x(self):
> print 'x method'
> def __getattr__(self, attr):
> print 'in __getattr__ method'
> return attr
> c = C()
> c.x --> print in __getattr__ method, then throw TypeError: 'str'
> object is not callable
>
Prim wrote:
> First, sorry about my poor english.
> Put these in IPython under ubuntu.
>
-
> class C:
> def __init__(self):
> self.x = 1
> def print(self):
> print self.x
> c = C()
> c.x --
First, sorry about my poor english.
Put these in IPython under ubuntu.
-
class C:
def __init__(self):
self.x = 1
def print(self):
print self.x
c = C()
c.x --> 1, so c.x mean a attr of c named