[Tutor] Python Docs (Was: Reformatting phone number)

Kent Johnson kent37 at tds.net
Fri Aug 22 23:01:29 CEST 2008


On Fri, Aug 22, 2008 at 4:23 PM, Dotan Cohen <dotancohen at gmail.com> wrote:
> 2008/8/22 Lie Ryan <lie.1296 at gmail.com>:
>> 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) ).
>
> If I know their names :(

Not necessarily. dir(object) will show you the names of the methods of
the object, then you can get help on individual methods. For example
to explore string methods:
dir('') lists all string methods, including e.g. endswith
help(''.endswith) gives help for the endswith method

Also
help(type(''))
gives the help for class str without having to know its name.

Kent


More information about the Tutor mailing list