Google Π³Ρ€ΡƒΠΏΠ΅ вишС Π½Π΅ ΠΏΠΎΠ΄Ρ€ΠΆΠ°Π²Π°Ρ˜Ρƒ Π½ΠΎΠ²Π΅ Usenet постовС Π½ΠΈ ΠΏΡ€Π°Ρ›Π΅ΡšΠ°. ΠŸΡ€Π΅Ρ‚Ρ…ΠΎΠ΄Π½ΠΈ ΡΠ°Π΄Ρ€ΠΆΠ°Ρ˜ ΠΎΡΡ‚Π°Ρ˜Π΅ Π²ΠΈΠ΄Ρ™ΠΈΠ².

console command to get the path of a function

0 ΠΏΡ€Π΅Π³Π»Π΅Π΄Π°
ΠŸΡ€Π΅Ρ’ΠΈ Π½Π° ΠΏΡ€Π²Ρƒ Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½Ρƒ ΠΏΠΎΡ€ΡƒΠΊΡƒ

mattia

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 07:45:4020.12.09.
–
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

Irmen de Jong

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 07:53:1820.12.09.
–

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

mattia

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 08:08:2120.12.09.
–

Perfect, thank you.

mattia

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 08:13:4320.12.09.
–
Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto:

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

Peter Otten

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 08:30:2120.12.09.
–
mattia wrote:

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

Dave Angel

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 10:34:4620.12.09.
– mattia, pytho...@python.org

If you know what module it's in, you can use
themodule.__file__

But realize that this will only work if the module has been imported,
and might not if the module is implemented in C.

DaveA

Terry Reedy

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 15:02:1220.12.09.
– pytho...@python.org
On 12/20/2009 7:45 AM, 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?).

On Windows and I believe other systems, for the stdlib, 'import x'
imports .../Pythonx.y/Lib/x


pograph

Π½Π΅ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°Π½ΠΎ,
20. 12. 2009. 15:40:4220.12.09.
–

Not always. For example, os.path is actually in one of ntpath.py,
posixpath.py, or macpath.py.

0 Π½ΠΎΠ²ΠΈΡ… ΠΏΠΎΡ€ΡƒΠΊΠ°