Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Peter Otten
Roc Zhou wrote: > I'm sorry but I still have a question, look at this example: class test: > ... def __init__(self): > ... self.x = 1 > ... def __getattr__(self, attr_name): > ... print attr_name > ... if attr_name == 'y': > ... return 2 > ...

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Gabriel Genellina
En Fri, 22 Jun 2007 03:43:26 -0300, Roc Zhou <[EMAIL PROTECTED]> escribió: > I'm sorry but I still have a question, look at this example: class test: > ... def __init__(self): > ... self.x = 1 > ... def __getattr__(self, attr_name): > ... print attr_name > ...

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Gabriel Genellina
En Fri, 22 Jun 2007 02:48:50 -0300, Roc Zhou <[EMAIL PROTECTED]> escribió: > I know what's wrong. Thank you. And I think > try: > return self.__dict__[attr_name] > is unnecessary, because python will do it itself for us. Exactly; by the time __getattr__ is called, you already know attr_name

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
I'm sorry but I still have a question, look at this example: >>> class test: ... def __init__(self): ... self.x = 1 ... def __getattr__(self, attr_name): ... print attr_name ... if attr_name == 'y': ... return 2 ... else: ... raise Att

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
return hex(id(self)) On 6 22 , 1 48 , Roc Zhou <[EMAIL PROTECTED]> wrote: > I know what's wrong. Thank you. And I think > try: > return self.__dict__[attr_name] > is unnecessary, because python will do it itself for us. > > So now I have to overload __str__, but how can I make self.__str__ >

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
I know what's wrong. Thank you. And I think try: return self.__dict__[attr_name] is unnecessary, because python will do it itself for us. So now I have to overload __str__, but how can I make self.__str__ print as builtin str(): at here, I want get the result like: ? On 6 22 , 12 55 , "Gab

Re: why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Gabriel Genellina
En Fri, 22 Jun 2007 00:30:43 -0300, Roc Zhou <[EMAIL PROTECTED]> escribió: > Now I have to design a class that overload __getattr__, but after > that, I found the __repr__ have been affected. This is a simple > example model: You are creating many attributes with value "inexistent", even specia

why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
Now I have to design a class that overload __getattr__, but after that, I found the __repr__ have been affected. This is a simple example model: #!/usr/bin/env python class test: def __init__(self): self.x = 1 def __getattr__(self, attr_name): try: return self.__dic

why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
Now I have to design a class that overload __getattr__, but after that, I found the __repr__ have been affected. This is a simple example model: #!/usr/bin/env python class test: def __init__(self): self.x = 1 def __getattr__(self, attr_name): try: return self._

why __repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
Now I have to design a class that overload __getattr__, but after that, I found the __repr__ have been affected. This is a simple example model: #!/usr/bin/env python class test: def __init__(self): self.x = 1 def __getattr__(self, attr_name): try: return self._

__repr__ affected after __getattr__ overloaded?

2007-06-21 Thread Roc Zhou
Now I have to design a class that overload __getattr__, but after that, I found the __repr__ have been affected. This is a simple example model: #!/usr/bin/env python class test: def __init__(self): self.x = 1 def __getattr__(self, attr_name): try: return self.