[Tutor] Python 3.2 - difference between out of dir() and help()

Flynn, Stephen (L & P - IT) Steve.Flynn at capita.co.uk
Thu Mar 8 13:01:54 CET 2012


Pythonistas,

 

                Tinkering around this morning and noticed the following
when I created a tuple and asked for a dir() on it and some help() on
it.

 

 

>>> x=('rod','jane','freddy')

>>> dir(x)

['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__',
'__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

>>> help(x)

Help on tuple object:

 

class tuple(object)

 |  tuple() -> empty tuple

[etc... snipped for brevity]

 

 

                All pretty standard stuff. I did however notice that the
dir(x) told me about __class__, __reduce__ and __reduce_ex__ where the
help(x) made no mention of them. Why is this difference? I presume the
two commands using different means of getting at and displaying the
methods for an object?

 

                Is help() giving me all of the useful methods an object
has which I'm encouraged to make use of, whereas dir gives me a complete
list of everything that object can 'do' including those methods which
aren't really meant for public consumption?

 

 

P.S. Posting from work, so I've configured this mail software to post to
this address in plain text. I'm hoping this email is going to get
converted to plain text when I hit send, as it looks decidedly html/rich
text as I type...

 

Steve Flynn | Technical Architect | Life & Pensions Services | Capita |
The Grange, Bishops Cleeve, GL52 8XX | 01242-670864

Part of Capita plc www.capita.co.uk <http://www.capita.co.uk/> 

 

Capita Life & Pensions Services Limited is registered in England No
4359665

Capita Life & Pensions Regulated Services Limited is registered in
England No 2424853

Registered office: 71 Victoria Street, Westminster, London SW1H 0XA

 

Capita Life & Pensions Regulated Services Limited is authorised and
regulated by the Financial Services Authority.

 



This email and any attachment to it are confidential.  Unless you are the intended recipient, you may not use, copy or disclose either the message or any information contained in the message. If you are not the intended recipient, you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, unless otherwise stated.  All copyright in any Capita material in this email is reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from the receipt, use or transmission of this email to the fullest extent permitted by law.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120308/ec46fd52/attachment-0001.html>


More information about the Tutor mailing list