python import error, what's wrong?

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Wed Aug 3 03:14:59 EDT 2011


smith jack wrote:
> I am using pydev plugin in eclipse, all things works just as well
> but now i have confronted with a confusing problem, that is i can
> import a module write by myself successfully, but when i try to run
> this program,
> error just shows up, what's wrong?
> 
> the directory structure is as follows:
> 
> src
>   org.test
>       A.py
>   org.lab
>       B.py

Python uses a dot as separator between different parts of nested structures, 
like e.g. the directories during import. I guess your directory naming 
conflicts with that. Try this structure instead:

  src
    org
      test
        A.py
      lab
        B.py

or maybe

  src
    org_test
      A.py
    org_lab
      B.py


> contents of A seems like:
> class A
>     ...
> 
> contents of B seems like:                  // I try to run B.py,
> python import error just appears, why?

"just appears" is not a sufficient discription of an error. I'd suggest 
reading Eric S. Raymond's excellent essay on "Asking Smart Questions", it 
will avoid such mistakes.

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list