import a user created python file as module

P

Phoe6

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
 
D

Dennis Lee Bieber

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.
Keyword: PythonPath

Second factor -- commonly one would expect to find the "importER" at
the top level with the "importED" in subdirectory <G>
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
A

Amit Khemka

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.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top