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 6 1434 st****@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.
--
Hans Nowak http://zephyrfalcon.org/
Thank you Hans. Could you give me a simple sample of using inspect?
Hans Nowak wrote: st****@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
Use the dir() function
dir(myClass)
returns a list of strings
-Dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Olivier Lefevre |
last post by:
Python 2.3
>>> def foo():
.... foo.a = 1
....
>>> vars(foo)
{}
>>> foo()
>>> vars(foo)
{'a': 1}
>>>
|
by: Fernando Rodriguez |
last post by:
Hi,
What's the syntax to add an attribute to a function form the function body?
For example, instead of doing:
def fn():
return 1
fn.error = "Error message"
print fn.error
|
by: Francis Avila |
last post by:
A little annoyed one day that I couldn't use the statefulness of
generators as "resumable functions", I came across Hettinger's PEP 288
(http://www.python.org/peps/pep-0288.html, still listed as...
|
by: george young |
last post by:
I recently found myself writing something like:
def get_connection():
if tcp_conn():
if server_allows_conn():
return 'good_conn'
else:
return 'bad_auth'
else:
return 'no_server'
|
by: John L. Clark |
last post by:
I am curious as to the rationale, and effect, of having default
namespaces not applying (directly) to attributes (see
http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute
without a...
|
by: Samuel M. Smith |
last post by:
I have been playing around with a subclass of dict wrt a recipe for
setting dict items using attribute syntax.
The dict class has some read only attributes that generate an
exception if I try to...
|
by: KraftDiner |
last post by:
I was under the assumption that everything in python was a refrence...
so if I code this:
lst =
for i in lst:
if i==2:
i = 4
print lst
I though the contents of lst would be modified.....
|
by: redefined.horizons |
last post by:
I've been reading about Python Classes, and I'm a little confused about
how Python stores the state of an object. I was hoping for some help.
I realize that you can't create an empty place holder...
|
by: John F. Holliday |
last post by:
I need to use the ActiveDirectoryMembershipProvider in my application.
I have setup the provider in the web config, etc. When I use the ASP.NET
configuration utility and select the Security tab, it...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |