How to find documentation about methods etc. for iterators

Tim Chase python.list at tim.thechases.com
Thu Apr 10 05:54:29 EDT 2008


>     First question, what sort of 'thing' is the file object, I need to
>     know that if I'm to look up ways of using it.

you can always use

   type(thing)

to find out what type it is.

>     Second question, even if I know what sort of thing a file object
>     is, how do I find methods applicable to it and/or functions
>     applicable to it?

If you don't have a web-connection under your finger tips, using

   dir(thing)
   help(thing)
   help(thing.method)

will tell you most of what you need to know.  There's the 
occasional gap, and it doesn't always work when the underlying 
object is out in C-land, rather than a pure Python object that's 
well-designed with doc-strings (personal complaint about 
mod_python's failure to return dir() contents last I checked). 
But for the most part I can just pull up a console debug-session 
with Python, enter enough to get an instance of the object in 
question, and then use the above commands.

This for me is Python's chief selling point:  dir()....dir() and 
help().  Python's two selling points are dir(), help(), and very 
readable code.  Python's *three* selling points are dir(), 
help(), very readable code, and an almost fanatical devotion to 
the BFDL.  Amongst Python's selling points are such elements as 
dir(),  help()...I'll come in again. </python>

> It's a common problem in all sorts of computer fields, if you know the
> name of what you want it's easy to find out details of how to use it
> but if you don't know its name (or even if it exists) it's much more
> difficult to find.

All Monty Python-quoting aside, Python has solved this (and gives 
3rd-party library developers the tools to solve as well) problem 
of discoverability using dir() and help().

-tkc







More information about the Python-list mailing list