[Python-Dev] Module properties for C modules (original) (raw)
Guido van Rossum guido at python.org
Thu May 1 22:02:19 CEST 2008
- Previous message: [Python-Dev] Module properties for C modules
- Next message: [Python-Dev] Module properties for C modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, May 1, 2008 at 12:32 PM, Christian Heimes <lists at cheimes.de> 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', 'reduceex', '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/)
- Previous message: [Python-Dev] Module properties for C modules
- Next message: [Python-Dev] Module properties for C modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]