modules...n methods

belinda thom bthom at cs.hmc.edu
Fri Jan 12 15:40:42 EST 2007


On Jan 12, 2007, at 8:56 AM, Bjoern Schliessmann wrote:

> lee wrote:
>
>> whats the way to read the sourcecode of methods
>
> Easy. Look up the .py file and open it in an editor of your choice.
> Those files are, for example, in "/usr/lib/python".
>
>> and built in functions?

This becomes a lot easier if you use IPython (which embellishes the  
python shell in many useful ways). For instance, I did a "dir 
(__builtins__)" to find out what some of the builtin functions were.  
One was called "zip". Here's what I do in IPython to get help on that  
function:

In [2]: zip??
Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in function zip>
Namespace:      Python builtin
Docstring [source file open failed]:
     zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]

     Return a list of tuples, where each tuple contains the i-th element
     from each of the argument sequences.  The returned list is  
truncated
     in length to the length of the shortest argument sequence.

Note that IPython's prompt is (by default) different than pythons--- 
the "In[<some number>]:". Any identifier you have a question about  
will produce summary info via "<identifier>?" and summary + source  
via "<identifier>??".

HTH
--b



More information about the Python-list mailing list