我在Windows 10
下使用Python 3
和Jupyter
。你知道吗
我有两个模块:mod_main
和mod_sub
。我想将各种模块(在本例中,只有os
)从mod_sub
导入mod_main
。对我有效的方法如下:
模式_主.py
from pathlib import Path # works with / for any OS
import sys
sys.path.append(str(Path('C:/MyApps/Python_Base')))
from dummypackage.mod_sub import *
#from dummypackage import mod_sub
def print_path():
print(os.path.realpath(__file__))
模式_sub.py公司
import os
print('mod_sub is imported')
然后在C:\MyApps\Python_Base
下的Jupyter笔记本上运行以下内容
from dummypackage import mod_main
import importlib
importlib.reload(mod_main)
mod_main.print_path()
现在,我有几个问题:
from dummypackage import mod_sub
,那么我将无法访问其他导入的modeule(os
)。那么,这里的最佳做法是什么?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐