导入模块,我不知道是否有做类似蟒蛇:在包命名空间
import scipy as sp
from scipy import interpolate as sp.interpolate
这是不允许的某些标准方式。
具体做法是:
我想知道是否有某种原因,为什么上面是不允许的。如果我正在开发我自己的包foo,尽可能少地污染它的名称空间似乎是合理的。
之类的东西
import scipy as sp __import__('scipy.interpolate')
做的工作,但不是所有的美好和文档建议不要使用
__import__
,如无绝对必要。同样import importlib import scipy as sp importlib.import_module('scipy.interpolate',sp)
做工作,但它仍然是丑陋的,甚至更长的时间,并把导入库命名空间中的...
我不认为它污染了命名空间来使用'进口SciPy的作为sp'看http://programmers.stackexchange.com/questions/187403/import-module-vs-from-module-import-function – rtrwalker
这不是'导入scipy sp',而是许多导入scipy.xxx,随后使用导入scipy的积分,插值,信号,...子模块。我想把它们都放在'sp' – user2340231