> 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
And yes, it is more to type ;)
--
http://mail.python.org/mailman/listinfo/python-list
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
>
> 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
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
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
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
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
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