console command to get the path of a function

Peter Otten __peter__ at web.de
Sun Dec 20 08:30:21 EST 2009


mattia wrote:

> Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto:
> 
>> On 12/20/2009 1:45 PM, mattia wrote:
>>> Hi all, is there a way in the python shell to list the path of a
>>> library function (in order to look at the source code?).
>>>
>>> Thanks, Mattia
>> 
>> something like this?
>> 
>>  >>> import inspect
>>  >>> import os
>>  >>> inspect.getsourcefile(os.path.split)
>> 'C:\\Python26\\lib\\ntpath.py'
>>  >>> print inspect.getsource(os.path.split)
>> def split(p):
>>      """Split a pathname.
>>   ...
>>   ...
>> 
>> 
>> --irmen
> 
> Ok, but how can I retrieve information about built-in functions (if any)?
> 
>>>> inspect.getsourcefile(itertools.product)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\Python31\lib\inspect.py", line 439, in getsourcefile
>     filename = getfile(object)
>   File "C:\Python31\lib\inspect.py", line 406, in getfile
>     raise TypeError('arg is a built-in class')
> TypeError: arg is a built-in class

To get to the source of functions written in C you have to download the 
source distribution, or you can browse the subversion tree:

http://svn.python.org/view/python/trunk/Modules/itertoolsmodule.c?view=markup

Peter



More information about the Python-list mailing list