How Do I get Know What Attributes/Functions In A Class?
Kent Johnson
kent37 at tds.net
Mon Feb 21 07:24:54 EST 2005
Hans Nowak wrote:
> steven at lczmsoft.com wrote:
>
>> Hi,
>>
>> I'm new to python. Given a class, how can I get know what
>> attributes/functins in it without dig into the source?
>
>
> Use the dir function:
>
> >>> from smtplib import SMTP
> >>> dir(SMTP)
> ['__doc__', '__init__', '__module__', 'close', 'connect', 'data',
> 'debuglevel', 'docmd', 'does_esmtp', 'ehlo', 'ehlo_resp', 'expn',
> 'file', 'getreply', 'has_extn', 'helo', 'helo_resp', 'help', 'login',
> 'mail', 'noop', 'putcmd', 'quit', 'rcpt', 'rset', 'send', 'sendmail',
> 'set_debuglevel', 'starttls', 'verify', 'vrfy']
>
> To get more detailed information than just a list of names, see the
> inspect module.
Or use 'help' (which is build on top of inspect):
>>> from smtplib import SMTP
>>> help(SMTP)
Help on class SMTP in module smtplib:
class SMTP
| This class manages a connection to an SMTP or ESMTP server.
| SMTP Objects:
| SMTP objects have the following attributes:
| helo_resp
| This is the message given by the server in response to the
| most recent HELO command.
etc.
Kent
More information about the Python-list
mailing list