Exploring Attributes and Methods

Paul McGuire ptmcg at austin.rr.com
Thu Mar 6 14:35:06 EST 2008


On Mar 6, 1:14 pm, "keios.ti... at gmail.com" <keios.ti... at gmail.com>
wrote:
> Hi,
>  Is there a python command that allows me to extract the names (not
> values) of the attributes of a class.
>
> example
>
> Class Sample:
>     fullname = 'Something'
>
> How can I know that this class has an attribute called 'fullname'?
>
> I hope my question is clear.
> Thanks

If you had posted actual working code, "Class" would be all lower case
("class").  But we get the drift (in general, though, when posting
questions about examples from your code, best to copy-paste the actual
code, not a paraphrasing of it):

print Sample.__dict__.keys()

prints:

['__module__', 'fullname', '__doc__']


-- Paul



More information about the Python-list mailing list