tags:

views:

368

answers:

5

I've recently started with Python, and am enjoying the "batteries included" design. I'e already found out I can import time, math, re, urllib, but don't know how to know that something is builtin rather than writing it from scratch.

What's included, and where can I get other good quality libraries from?

+3  A: 

The Python Global Module Index (http://docs.python.org/modindex.html) lists out every module included in Python 2.6.

Sourceforge has all sorts of good Python modules - one that came in handy for me recently was PyExcelerator, a module for writing straight to MS Excel workbooks. The Python Package Index, (http://pypi.python.org/) is also a good source of Python modules.

Patrick Harrington
+14  A: 

Firstly, the python libary reference gives a blow by blow of what's actually included. And the global module index contains a neat, alphabetized summary of those same modules. If you have dependencies on a library, you can trivially test for the presence with a construct like:

try:
    import foobar
except:
    print 'No foobar module'

If you do this on startup for modules not necessarily present in the distribution you can bail with a sensible diagnostic.

The Python Package Index plays a role similar to that of CPAN in the perl world and has a list of many third party modules of one sort or another. Browsing and searching this should give you a feel for what's about. There are also utilities such as Yolk which allow you to query the Python Package Index and the installed packages on Python.

Other good online Python resources are:

ConcernedOfTunbridgeWells
+10  A: 

run

pydoc -p 8080

and point your browser to http://localhost:8080/

You'll see everything that's installed and can spend lots of time discovering new things. :)

Dustin
+1...it saves a lot of time working off the docs of what you actually have installed over trying to ensure what you're reading on the web is the same as your local installation.
Matthew Trevor
A: 

This is not directly related to your question, but when you're in the python console, you can call help() on any function and it will print its documentation.

also, you can call dir() on any module or object and it will list all of its attributes, including functions.

This useful for inspecting contents of a module after you've imported it.

>>> import math
>>> dir(math)
['__doc__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
>>> help( math.log )
Help on built-in function log in module math:

log(...)
    log(x[, base]) -> the logarithm of x to the given base.
    If the base not specified, returns the natural logarithm (base e) of x.
hasen j
+1  A: 

Doug Hellman's blog covers lots of built-in libraries in depth. If you want to learn more about the standard library you should definitely read through his articles.

ianb