import a user created python file as module

Amit Khemka khemkaamit at gmail.com
Mon Jul 31 02:44:42 EDT 2006


On 30 Jul 2006 23:07:07 -0700, Phoe6 <orsenthil at gmail.com> wrote:
> Hi,
>      I have the following directory structure in my project.
> Base:
>          file1.py
>          file2.py
>          Directory1:
>                        file1-dir1.py
>
> I am able to import file1 into file2.py
> What I need to do is, import file1 in the file file1-dir1.py.
> I did not create the entire dir structure as package. Adding
> __init__.py file in both Base: as well as Directory1: is not helpful. I
> am unable to import file1 in the file1-dir1.py. It is not able to find
> the path of the file1.py.
>
> How and what should I do to import file1.py into file1-dir1.py ? Please
> give me some references to the tutorial topic which I can study as
> well.

 Modify the path where python searches for modules, for example in
file1-dir1.py add:

 import sys
 sys.path.append("/path/to/Base")
 import file1


cheers,
amit.
-- 
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list