我正在创建一个供内部使用的python包&;它具有一些跨其他模块通用的内部功能。例如,以下功能正在其他模块中使用-
def GetLocalImage(WebImage):
ImageLink = WebImage.get("data-src")
FileName = ImageLink.split("/")[-1]
urllib.request.urlretrieve(ImageLink,FileName)
return(FileName)
如您所见,函数需要使用urllib
。以下是软件包的文件结构-
formatter
\ __init__.py
\ File1.py --> It would call GetLocalImage()
\ File2.py --> It would call GetLocalImage()
我的主程序使用from formatter import *
语句。我的问题是-
import urllib
&;功能李>
我终于明白了。我是这样解决的-
common.py
common.py
中,我有import urllib.request
File2.py
,我像from .common import *
一样导入import formatter
__init__.py
文件中,我保存了-我想我们可以跳过
__init__.py
文件(不确定)。希望这对将来的人有所帮助相关问题 更多 >
编程相关推荐