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.p开发者_开发问答y module contains:
shell.py:
from os.path import 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?
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
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(...)
精彩评论