Viewing contents of an object

M.-A. Lemburg mal at lemburg.com
Fri Aug 20 09:52:59 CEST 1999


The Blue Wizard wrote:
> 
> Hi Pythoneers!
> 
> I would like to be able to view the content of an arbitrary object, e.g.
> view(myObject) would print
> class: myClass
> class variables:
>     counter   = 6
>     topicoftheday = "Python is fun!"
> instance variables:
>     x = 4
>     y = 7
> 
> Thanks!

Try hack.py which you can download from my Python Pages. You can
use that code to build your own versions...

>>> hack.show(p,5)
<Proxy.Proxy.InstanceProxy for __main__. ...
    __class__ :
        <class Proxy.Proxy.InstanceProxy at 80ea ...
            __name__ :
                'InstanceProxy'
            __bases__ :
                ()
            __dict__ :
                __doc__ :
                    ' Proxy that wraps Python instances tran ...
                __frozen__ :
                    1
                __getattr__ :
                    <function __getattr__ at 80f7838>
                __init__ :
                    <function __init__ at 80f41e8>
                __module__ :
                    'Proxy.Proxy'
                __repr__ :
                    <function __repr__ at 80f7818>
                __setattr__ :
                    <function __setattr__ at 80eaea8>
    __dict__ :
        proxy_getattr :
            <built-in method proxy_getattr of Proxy  ...
                __name__ :
                    'proxy_getattr'
                __members__ :
                    __doc__ : 'proxy_getattr(name)\012\012Tries to get ...
                    __name__ : 'proxy_getattr'
                    __self__ : <Proxy object at 80ecce8>
        proxy_object_repr :
            '__main__.C'
        proxy_setattr :
            <built-in method proxy_setattr of Proxy  ...
                __name__ :
                    'proxy_setattr'
                __members__ :
                    __doc__ : 'proxy_setattr(name,value)\012\012Tries  ...
                    __name__ : 'proxy_setattr'
                    __self__ : <Proxy object at 80ecce8>

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   133 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list