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


Groups > comp.lang.python > #68570

Re: [Python-Dev] Issues about relative& absolute import way for Portingfrom python2.4 to python2.7

From Peter Otten <__peter__@web.de>
Subject Re: [Python-Dev] Issues about relative& absolute import way for Portingfrom python2.4 to python2.7
Date 2014-03-20 08:21 +0100
Organization None
References <tencent_2BE3693E682BB54F2047A4BE@qq.com>
Newsgroups comp.lang.python
Message-ID <mailman.8291.1395300082.18130.python-list@python.org> (permalink)

Show all headers | View raw


北冰洋 wrote:

> I just wrote a sample like this:
> testPy/
>          __init__.py
>          client.py
>          SoamFactory.c
>          SoamFactory.so
>          soamapi.py
>          sample/testP.py
> export PYTHONPATH=$(TEST_LOCATION):$(TEST_LOCATION)/testPy

> I found that soamapi was imported twice, and I investigated this is

> I don't know how to fix it. Is there any official way about how to porting
> this scenario or better idea?

Without looking into the details -- I believe that your problem stems from 
having a path into the package:

> export PYTHONPATH=$(TEST_LOCATION):$(TEST_LOCATION)/testPy

The above means that a module testPy.foo can also successfully be imported 
as foo. Try changing the path to

export PYTHONPATH=$(TEST_LOCATION)

If you get failing imports change every failing import

import foo

to

from testPy import foo

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


Thread

Re: [Python-Dev] Issues about relative& absolute import way for Portingfrom python2.4 to python2.7 Peter Otten <__peter__@web.de> - 2014-03-20 08:21 +0100

csiph-web