On 19 Dec 2010, at 21:26, Steven D'Aprano
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']
I think the issue that Elke is pointing out is that dir(Spam) knows nothing about y (whereas it would if you used __slots__). One answer is to have class member defaults for all instance members. Michael
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 _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas