472,993 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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 1819
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
11
by: Jim | last post by:
Hi, I have created an import module. And would like to access a function from the main script, e.g., file abc.py: ################### def a(): m() return None
2
by: gbin,Zhou | last post by:
Hi,all. I see from "http://docs.python.org/tut/node11.html" that "Name spaces are created at different moments and have different lifetimes. The namespace containing the built-in names is created...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.