importing a package

flupke flupke at nonexistingdomain.com
Wed Jun 22 06:29:47 EDT 2005


Hi,

I developed a package with a structure like this
src/
    tesfile.py
    dir1/
        __init__.py
        file1.py
    dir2/
        __init__.py
        file2.py

The testfile is meant to try the code out that is specified in file1.py 
and file2.py

Now i have another project where i want to use the code from that package.
The structure of that project:

src/
     file3.py
     dir3/
         __init__.py
         file4.py

To use it, i copied the package in the root of the project:
src/
     file3.py
     dir3/
         __init__.py
         file4.py
     package/
            __init__.py
            dir1/
                __init__.py
                file1.py
            dir2/
                __init__.py
                file2.py

In my code (file3.py) i then do an "import package.dir1.file1 as myobj" 
and access a class like this:
	myobj.LMyClass()

(where myobj and LMyClass are decent names. Used these as example)

That works but i get an error in the package files.
I then get an error in package/dir1/file1.py on an import statement 
specified in that file1.py that says import dir2.file2

How come this works as standalone project and not when i try to use it 
as in situation 2 it doesn't seem to find module file2.py ?
How can i solve that?

Thanks
Benedict



More information about the Python-list mailing list