473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Jul 18 '05 #1
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/
Jul 18 '05 #2
Thank you Hans. Could you give me a simple sample of using inspect?

Jul 18 '05 #3
<st****@lczmsoft.com> wrote in message news:11**********************@l41g2000cwc.googlegr oups.com...
Thank you Hans. Could you give me a simple sample of using inspect?


http://www.python.org/doc/current/li...e-inspect.html

George
Jul 18 '05 #4
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

Jul 18 '05 #5
Thank you All !

Jul 18 '05 #6
Use the dir() function

dir(myClass)

returns a list of strings

-Dan
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Olivier Lefevre | last post by:
Python 2.3 >>> def foo(): .... foo.a = 1 .... >>> vars(foo) {} >>> foo() >>> vars(foo) {'a': 1} >>>
6
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
9
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...
8
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'
1
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...
6
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...
161
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.....
3
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...
1
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...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.