Custom Search

Friday, April 2, 2010

Use the built in function 'dir' to inspect objects in python

Use the built in function 'dir' to inspect objects in python

• Use the built in function 'dir' to inspect objects
• '__doc__': class documentation string
• '__class__': class for the instance

>>> import geom1
>>> i1 = geom1.Circle(0, 0, 2)
>>> dir(i1)
['__doc__', '__init__', '__module__', 'area', 'radius', 'x', 'y']
>>> print i1.__doc__
A 2D circle.
>>> print i1.__class__
geom1.Circle

>>> type(i1)

>>> type(Circle)

>>> type(i1.radius)

>>> type(i1.area)

Publish Post

No comments:

Post a Comment