473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Re: problem with import / namespace

ohad frand wrote:
Hi
I have a problem that the solution to it must be very simple but i
couldnt fint it's answer in the internet so far (i searched for couple
of days)
the problme is as follows:

i have two directories e.g. "\\1" and "\\2"
in each directory i have two files with the same names e.g. "tmp1.py"
and "tmp2.py"
So this is what you have:

/1/tmp1.py
/1/tmp2.py
/2/tmp1.py
/2/tmp2.py
each tmp2.py file imports tmp1 from its same directory (import tmp1) -
thats the problem
if i execute one file (\\1\tmp2.py) than the execution is ok
but when i try after that to execute the second file (\\2\tmp2.py)
than the tmp1 file from the wrong directory ( - directory 1 in this
case) is imported instead.
When you try to import a module, python starts to search for it. The was
it does the search is very well defined. It mostly depends on the
current directory and sys.path. You can read more about this here:

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

This is very basic thing - you should read and go through the tutorial
before asking questions like this. :-)
i tried many things to try to solve it, i removed the previous path
from sys.path and added the new one, i tried to change current working
directory with os.chdir()
I tried to delete from locals and from globals the name tmp1 before
running the second file but nothing worked.
please help
The problem is still not well defined. Python works as expected and
documented, but apparently you do not know how to import 1/tmp2.py from
2/tmp1.py. There are several ways to do it, and we cannot tell which
one is correct. It depends on what are these modules for.

Here are the solution that you would use (most likely) as a beginner:
#1 first, rename your "1" and "2" directories to "one" and "two". If you
are creating a package with modules, then you have to define the
package's name with its directory. Since identifiers cannot begin with
digits in Python, you need to use an identifier-like name for your
subdirs. It is a good idea anyway. A package name called "1" would tell
nothing about what it does?
#2 place your main application in /app/app.py
#3 create /app/one/__init__.py and /app/two/__init__.py files (they can
be empty)
- inside your app.py file either make sure that the current dir is /app,
or insert /app in the first place in sys.path
Then for example, inside two/tmp1.py you can do this:
import one.tmp1
import one.tmp2
import two.tmp1

one.tmp1.somefunc()
two.tmp1.somefunc()
You got the idea.

Laszlo
Jun 27 '08 #1
0 1882

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse...
4
by: Bruce W. Roeser | last post by:
All, I'm reading a book by Charles Petzold (Programming VS.Net). Pretty good content but am confused about the difference. From the text: ...
14
by: Mark B | last post by:
Our webhost (www.usbusinessweb.net) had a W2K IIS5 server crash after a scheduled hard-boot occurred during a ms-security patch install overnight. They couldn't get the server working again so they...
2
by: Carmit | last post by:
Hi, I'm trying to build a proxy for this webservice: http://webservices.sabre.com/wsdl/sabreXML1.0.00/tpf/EndTransactionLLSRQ.wsdl I'm getting the following error: Error: Unable to import...
1
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
1
by: Alex Maghen | last post by:
I've been using my installed VS 2005 for several months with no problem. Suddenly, something strange is happeneing and I'm not sure if it's something I'm missing in ASP.NET or something that's...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.