3

I am trying to import a module from a package set up as per instructions from Modules Python Tutorial. My directory tree is:

$ pwd /home/me/lib/python/pygplib $ ls * __init__.py atcf: atcf.py __init__.py 

I am able to import pygplib but pygplib.atcf does not seem to exist:

In [1]: import pygplib In [2]: dir(pygplib) Out[2]: ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] 

What am I doing wrong? All my __init__.py files are blank. Thank you.

1
  • Have you tried import pygplib.atcf.atcf to get what's in that file? Commented Aug 8, 2012 at 18:21

2 Answers 2

3

atcf is not imported automatically into the pygplib namespace, but you can arrange for this to happen by putting

import atcf 

in pygplib/__init__.py.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this is exactly what I need, as I would like to have submodules available in the namespace on package import.
Also note that if you want the stuff in atcf.py to be in the pygplib.atcf namespace, you'll want to put from atcf import * in pyglib/atcf/__init__.py.
3

Submodules don't get imported when you import the top package, and thus don't appear in dir. Instead, do

from pygplib import atcf 

Or

from pygplib.atcf import atcf 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.