Eike Welk wrote:
My positive attitude towards this syntax comes from the only weakness that Python IMHO has: You can't easily see which data attributes an instance has.
What's wrong with dir(obj) and vars(obj)?
class Spam: ... x = 1 ... def __init__(self): ... self.y = 2 ... obj = Spam() vars(obj) {'y': 2} dir(obj) ['__doc__', '__init__', '__module__', 'x', 'y']
Python has *awesome* self-inspection abilities -- there's very little you can't easily find out about an object, so much so that people sometimes complain that you can't really hide information from the caller in Python -- there are no truly private attributes, only private by convention. See also the inspect module.
This information is hidden in __init__, and sometimes elsewhere. I think a mechanism like slots should be the norm, and dynamism the exception.
Such a language would no longer be Python. Perhaps it will be a better language, perhaps a worse one, but it won't be Python. By the way, __slots__ is intended as a memory optimization, not as a mechanism for defeating Python's dynamic nature. -- Steven