468,110 Members | 1,802 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

import a user created python file as module

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.

Thanks,
Senthil

Jul 31 '06 #1
2 1667
On 30 Jul 2006 23:07:07 -0700, Phoe6 <or*******@gmail.comwrote:
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.
Jul 31 '06 #2

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.
And some reference:

http://docs.python.org/tut/node8.html

Regards,
Rob

Jul 31 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.