On Thu, May 1, 2008 at 12:32 PM, Christian Heimes <[EMAIL PROTECTED]> wrote:
> Guido van Rossum schrieb:
>
> > But wouldn't this mean that those properties would no longer be
>  > available in the module's __dict__?
>
>  Correct. Module properties would behave exactly like instance
>  properties. They don't appear on the instance's __dict__ attribute, too.
>
>  By the way I was astonished that the vars() function dones't show
>  properties but dir() does list them.

"Astonished" sounds stronger than you probably meant it. :-)

>  >>> class Example(object):
>  ...     @property
>  ...     def x(self):
>  ...         return 42
>  ...
>  >>> example = Example()
>  >>> example.__dict__
>  {}
>  >>> vars(example)
>  {}
>  >>> dir(example)
>  ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
>  '__hash__', '__init__', '__module__', '__new__', '__reduce__',
>  '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'x']

They are intentionally different though -- dir() tries to give all the
attributes, while vars() only accesses __dict__.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to