Re: __getattr__ question

2006-06-10 Thread Laszlo Nagy
> print "item1" in dir(root) # False > print "item3" in dir(root) # True > > Is it the behavior you wanted? > Exactly. :-) Why I did not think of this? I'm always amazed when I see that Python can do anything we want. :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ question

2006-06-10 Thread [EMAIL PROTECTED]
And yes, it is more to type ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ question

2006-06-10 Thread [EMAIL PROTECTED]
Hello! > How can I determine if an attribute can be found in the usual places? print "item1" in dir(root) # False print "item3" in dir(root) # True Is it the behavior you wanted? -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ question

2006-06-10 Thread Laszlo Nagy
> > Either way is a few more characters to type, but it's far saner than > trying to distinguish between "real" and "fake" attributes. > I think you are right. I'll make up my mind. -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ question

2006-06-09 Thread Ben Cartwright
Laszlo Nagy wrote: > So how can I tell if 'root.item3' COULD BE FOUND IN THE USUAL PLACES, or > if it is something that was calculated by __getattr__ ? > Of course technically, this is possible and I could give a horrible > method that tells this... > But is there an easy, reliable and thread safe

Re: __getattr__ question

2006-06-09 Thread Alex Martelli
Andrew Robert <[EMAIL PROTECTED]> wrote: > If I remember correctly, this behavior depends on how the class is > created (classic mode versus modern). > > Modern > > class foo(object): > pass > > Classic ( pre python 2.2 I believe ) > > class foo(): No parentheses all

Re: __getattr__ question

2006-06-09 Thread Andrew Robert
If I remember correctly, this behavior depends on how the class is created (classic mode versus modern). Modern class foo(object): pass Classic ( pre python 2.2 I believe ) class foo(): pass The modern method of specifying object in the class def

Re: __getattr__ question

2006-06-09 Thread Ben Finney
Laszlo Nagy <[EMAIL PROTECTED]> writes: > This is from the Python documentation (fragment): > > __getattr__( self, name) > Called when an attribute lookup has not found the attribute in the > usual places (i.e. it is not an instance attribute nor is it found in > the class tree for self

Re: __getattr__ question

2006-06-09 Thread Laszlo Nagy
Here is a horrible solution. I could make it thread-safe by adding +30 lines. There must be a better solution. class TemplateItem(object): def __init__(self,name): self.name = name self.items = [] def __getattr__(self,name): self._getattr_was_called = True

__getattr__ question

2006-06-09 Thread Laszlo Nagy
Hello, This is from the Python documentation (fragment): __getattr__( self, name) Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self). name is the attribute name. This method