tags:

views:

29

answers:

2

I am consolidating many shell-like operations into a single module. I would then like to be able to do:

pyscript.py:
from shell import *
basename("/path/to/file.ext")

and the shell.py module contains:

shell.py:
import os.path.basename

The problem is that functions imported to the shell module are not available, since the import statement only includes functions, classes, and globals defined in the "shell" module, not ones that are imported.

Is there any way to get around this?

+2  A: 

It's not a bug, it's a feature :-)

If you import m1 in a module m2 and then import m2 into another module, it will only import things from m2, not from m1. This is to prevent namespace pollution.

You could do this:

shell.py:

import os.path
basename = os.path.basename

Then, in pyscript.py, you can do this:

from shell import * # warning: bad style!
basename(...)
leoluk
+2  A: 

Are you sure you're not just using the wrong syntax? This works for me in 2.6.

from shell import * 
basename("/path/to/file.ext")

shell.py:

from os.path import basename
Mark Ransom