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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Flynn, Steve (L & P - IT)

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

 

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.

 

 This message has been scanned for malware by Websense. www.websense.com


_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

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

Steven D'Aprano-8
Flynn, Stephen (L & P - IT) wrote:

>                 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?

Yes. Both help() and dir() attempt to give an "interesting" list of
attributes, and both have different ideas of what counts as "interesting".

There is no hard rules as to what they will give, consequently they may change
from version to version. Any differences are unlikely to be deliberate, but
merely side-effects of the specific implementation of each.

By the way, help() is a complete interactive environment. Just call help()
with no arguments and follow the prompts.


>                 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?

Nothing so specific.

See the documentation for both:

http://docs.python.org/library/functions.html#dir
http://docs.python.org/library/functions.html#help




--
Steven
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor