joedborg
joedborg

Reputation: 18343

Importing from Python subdirectories

This should be straight forward, but I'm not sure whether it's my Eclipse config or my Python.

I've got a 2 files /trunk/shared/foo/bar.py and /trunk/shared/foo/io.py

There is an __init__.py there too and in shared.

All I want to do is import io.py in bar.py. I've tried import io, import foo.io and import shared.foo.io (as well as trunk.shared.foo.io). None of these work, failing with the usual unresolved.

Cheers, Joe

Upvotes: 0

Views: 127

Answers (1)

Cédric Julien
Cédric Julien

Reputation: 80761

To allow something like this : import share.foo.bar

You should have something like this :

trunk/
      shared/__init__.py
             foo/__init__.py
                 bar.py
                 io.py

The __init__.py (they must be empty in this case) files are needed to tell to python that it found a python module (ie : something you could import).

Upvotes: 1

Related Questions