PS.

J

Jan Kaliszewski

dir(type(an_obj))

or more reliable:

list(vars(type(an_obj)))

(dir() uses __dir__ which can be implemented in any way, and default
implementation, accordinto to the docs, "attempts to produce the most
relevant, rather than complete, information").

I missed one important thing:

* dir(a_type) mostly applies to attributes of a_type *and* of its base
types/classes [1].
* vars() applies only to attributes of this particular type (AFAIN
vars(sth) and sth.__dict__ are practically the same).

Example:
['__class__', '__contains__', '__delattr__', '__delitem__',
'__dict__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__',
'__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem',
'setdefault', 'update', 'values'] ['__dict__', '__module__', '__weakref__', '__doc__']

Regards,
*j

[1] In Python 3.x *type* and *class* is practically the same. (though
built-in ones are denoted as *types* rather than *classes* -- using this
naming convention a *class* is simply a user-defined *type*).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top