How Do I get Know What Attributes/Functions In A Class?

S

steven

Hi,

I'm new to python. Given a class, how can I get know what
attributes/functins in it without dig into the source?

-
narke
 
H

Hans Nowak

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:
['__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.
 
K

Kent Johnson

Hans said:
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:
['__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):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
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top