[Tutor] Reformatting phone number

Lie Ryan lie.1296 at gmail.com
Fri Aug 22 18:48:49 CEST 2008


> Message: 4
> Date: Thu, 21 Aug 2008 12:13:58 +0200
> From: "Dotan Cohen" <dotancohen at gmail.com>
> Subject: Re: [Tutor] Reformatting phone number
> To: OmerT <Jaggojaggo+Py at gmail.com>
> Cc: "python-tutor." <tutor at python.org>
> Message-ID:
>         <880dece00808210313w20ef5063ia0ff0cdbd269f286 at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> 2008/8/21 OmerT <Jaggojaggo+Py at gmail.com>:
> > mostly, I google "docs.python" and the term or class I'm looking
> for.
> > Mind, this mainly works for modules or classes which came with the
> interpreter.
> >
> 
> Exactly- that only works for term, classes, and functions that you
> already know the name of. The php docs have a list of all the
> functions with a one-line description. It's very easy to find which
> funtion performs what one needs.
> 
> I would have never found the startswith() function with the current
> document structure. But I suppose that is subject for another thread,
> which I am sure would degrade quickly into a flamewar. I don't want to
> be the cause of that :)

You should also be aware of python's introspection abilities. If you
have an object, you could do help(object), dir(object) to get the help
file and a dictionary containing the members of the object (if run from
a script, you might need to add print statement, e.g. print
dir(object) ).

In the case of "finding" str.startswith (i.e. a class' members), you
could do this from the interactive prompt:

>>> help(str)
this will print the documentation of str module (and the documentation
for all its children too)

also, typing:
>>> help()
will open _interactive_ help with a prompt

>>> help('modules')
would list all available modules

>>> help('keywords')
would list all of python's reserved words

>>> help('topics')
would list some other topics you could pass to help()



The "online"[1] help is a very powerful tool, use it often. help() and
dir() can also be used from a script, although you might need to add
print statement.

[1] online refers to the fact that help() is generated from docstrings
on-the-fly, it is not related Internet at all. PS: There is also the
Internet version of the documentation



More information about the Tutor mailing list