Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18827

Re: import problems.

Date 2012-01-11 08:44 -0500
From Dave Angel <d@davea.name>
Subject Re: import problems.
References <4F0D8CF5.1090508@rece.vub.ac.be>
Newsgroups comp.lang.python
Message-ID <mailman.4645.1326289470.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 01/11/2012 08:21 AM, Antoon Pardon wrote:
> I have an import problem I can't figure out.
> I am using python 2.6.6 on a debian box
>
> In one directory (pylib) I have a file misc.py and
> the file testutil.py.
>
> -------------------- testutil.py ----------------------
>
> print "in", __name__
>
> from misc import Rec
>
> --------------------------------------------------------
>
> calling this file in that directory gives me this:
>
> $ python testutil.py
> in __main__
>
> In a neighbour directory I have the file ats
>
> ------------------------ atst ----------------------------
>
> import sys
>
> from os.path import join as pj, abspath
>
> print abspath("../pylib")
>
> sys.path.append(abspath("../pylib"))
>
> import testutil
>
> -----------------------------------------------------------
>
> Now calling this file in its directory gives me the following problem:
> $ python atst
> /local/home/apardon/src/projecten/pylib
> in testutil
> Traceback (most recent call last):
>   File "atst", line 9, in <module>
>     import testutil
>   File "/local/home/apardon/src/projecten/pylib/testutil.py", line 4, 
> in <module>
>     from misc import Rec
> ImportError: cannot import name Rec
>
> Why can I import Rec from misc in testutil when I call testutil.py 
> directly but not when testutil was imported itself?
In your first case, Rec.py was in the current directory, which is one of 
the specs in classpath.  In the second case, your current directory was 
somewhere else.



-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: import problems. Dave Angel <d@davea.name> - 2012-01-11 08:44 -0500

csiph-web