Hi,

I am attempting to view the source code of a module i have imported to a project but am having trouble finding its source. I had previously thought the command 'import' would look for a script in python paths named the same as the import name plus a '.py'. But, now I have a module that must be named differently and I am wondering how python finds the correct module to use and also how that I would go about finding the module?

Thanks -- Andrew

This is jsut off the top of my head, but its simewhere in he "lib" folder of your python installation.

if your on windows:

import sys

print sys.path


that will list the locations that python searches to look for modules, ie, to import it will scan those directories to find it. if you on another OS then i dont know the code - btu its a system variabel called python path isnt it?

Anyway - that shoudl get you started to finding th source code. hint: just look through the python folder, and youll find it eventually. The directory for python isnt athat hard to navigate, and just look for folde rnames that look right.


gdlk

Yes, that helped by seeing the path variable. Actually I had looked all through the directory structure looking for it but seems, come to find out, the folder name seems to be used as a reference. Then __init__ within directory is found and from there I can find the related scripts inorder of inclusion and such.

Thanks for your help -- Andrew

Hi,

I am attempting to view the source code of a module i have imported to a project but am having trouble finding its source. I had previously thought the command 'import' would look for a script in python paths named the same as the import name plus a '.py'. But, now I have a module that must be named differently and I am wondering how python finds the correct module to use and also how that I would go about finding the module?

Thanks -- Andrew

The following code lists most(im not sure, sorry) of modules used/provied by Python system.

import sys

for idx, k in enumerate( sys.modules.keys() ):
	print "|%d. %s %8s"%(idx+1, k, sys.modules[k])
	print '-'*100
..
|57. socket <module 'socket' from 'C:\Python25\lib\socket.pyc'>
----------------------------------------------------------------------------------------------------
|58. thread <module 'thread' (built-in)>
----------------------------------------------------------------------------------------------------
..
|63. os <module 'os' from 'C:\Python25\lib\os.pyc'>
----------------------------------------------------------------------------------------------------
..

hope this helps to some level.

katharnakh.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.