Doyon, Jean-Francois said:
But then, why does this code work ok?
class CrosslingualSupport: """ Mix-in class to provide content objects with support for cross-lingual properties when needed. """
def clearCrosslingualAttributes(self, lang): """ For a given language, remove all internal attributes related to it. """ 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? If so, Python doesn't mangle those names. See: http://docs.python.org/ref/atom-identifiers.html Also, what do you intend to communicate by naming __multilingualproperties__ with the leading and trailing underscores? Might want to read the style guide at http://www.python.org/peps/pep-0008.html if you haven't lately... see the "Naming Conventions" section. -- Paul Winkler http://www.slinkp.com