object.*

Tim Leslie tim.leslie at gmail.com
Thu Aug 26 11:56:59 EDT 2004


An approximation of this functionality can be obtained using the built
in dir() command. A quick example follows:
>>> class C:
...     def __init__(self):
...             self.a = 1
...             self.b = 2
...     def f(self):
...             return self.a + self.b 
... 
>>> c = C()
>>> dir(c)
['__doc__', '__init__', '__module__', 'a', 'b', 'f']
>>> ["c." + x for x in dir(c)]
['c.__doc__', 'c.__init__', 'c.__module__', 'c.a', 'c.b', 'c.f']
>>> map(eval, ["c." + x for x in dir(c)])
[None, <bound method C.__init__ of <__main__.C instance at
0x401ec50c>>, '__main__', 1, 2, <bound method C.f of <__main__.C
instance at 0x401ec50c>>]

Cheers,

Tim

On 26 Aug 2004 08:41:25 -0700, DeadWisdom <deadwisdom at wisefool.net> wrote:
> I think there should be an ability in python to write something like
> "object.*" which should return a dictionary object containing all the
> members and their values for the given object.  Maybe ".*" could be
> treated as an operator. ::shrug::
> 
> Perhaps the functionality already exists in some other syntax; if so
> please splain.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list