Anyone has a nice "view_var" procedure ?

Duncan Booth duncan.booth at invalid.invalid
Tue Jan 16 07:41:44 EST 2007


Neil Cerutti <horpner at yahoo.com> wrote:

> dir( [object]) 
>   
>   [...] The list is not necessarily
>   complete. If the object is a module object, the list contains
>   the names of the module's attributes. If the object is a type
>   or class object, the list contains the names of its attributes,
>   and recursively of the attributes of its bases. Otherwise, the
>   list contains the object's attributes' names, the names of its
>   class's attributes, and recursively of the attributes of its
>   class's base classes. The resulting list is sorted
>   alphabetically. [...]
> 
> It's unclear to me what attributes an object could have that
> aren't included in the above list.

For a start the potentially infinite list of attributes handled by 
__getattr__ or __getattribute__:

>>> class C(object):
	def __getattribute__(self, name):
		if name.startswith('weird'):
			return 42

		
>>> c = C()
>>> c.weirdattribute
42
>>> dir(c)
[]

Any objects which are actually implemented as C extensions are quite likely 
to have attributes that dir() cannot see.



More information about the Python-list mailing list