[Zope] Re: Problem with hasattr() and Zope 2.8.1
Paul Winkler
pw_lists at slinkp.com
Wed Oct 5 15:27:57 EDT 2005
>> for propertyname in [ propname for propname in
>> self.__multilingualproperties__.keys() if
>> self.__multilingualproperties__[propname][1] == True ]:
>> attname = '__' + propertyname + '_' + lang
>> if hasattr(self, attname): delattr(self, attname)
>>
>> As you see on the last line, I'm doing a hasattr() on an attribute
>> who's name starts with 2 underscores, and it works fine in this case
>> (has been for weeks, if not months).
>
> But do those names *end* with underscores as well?
(snip)
Oops, sent too quickly; actually it looks to me like they don't
(unless lang ends in "__").
However, it's not clear what "it works" means.
Your code above won't raise any exceptions, but it
shouldn't delete any attributes either :-)
>>> class Foo:
.... def __init__(self):
.... self.__blech = 1
.... self.__blah__ = 1
.... self._bloop = 1
.... def do(self):
.... print hasattr(self, "__blech")
.... print hasattr(self, "_Foo__blech")
.... print hasattr(self, "__blah__")
.... print hasattr(self, "_bloop")
....
>>> x = Foo()
>>> x.do()
False
True
True
True
--
Paul Winkler
http://www.slinkp.com
More information about the Zope
mailing list