关于模块调用的报错
本帖最后由 fc5igm 于 2021-6-20 17:42 编辑我有一个主程序,叫作test
在test里我试图调用模块proxy_ip.export
模块proxy_ip.export中的第一行是
import decoding.file as df
也就是下面这个报错中说未找到的那个模块
=================== RESTART: D:\python\works\project\test.py ===================
Traceback (most recent call last):
File "D:\python\works\project\test.py", line 2, in <module>
import proxy_ip.export as ip
File "D:\python\works\project\proxy_ip\export.py", line 1, in <module>
import decoding.file as df
ModuleNotFoundError: No module named 'decoding'
>>>
然而问题是,我这个叫做export的模块单独运行的时候,decoding.file是可以被成功调用的
但是通过test调用export再从export调用decoding中的file模块就失败了
求问原因
test
import urllib.request as urr
import proxy_ip.export as ip
url='http://www.whatismyip.com.tw'
proxy_support=urr.ProxyHandler(ip.get_ip())
opener=urr.build_opener(proxy_support)
response=opener.open(url).read().decode('utf-8')
print(response)
export
import decoding.file as df
def get_ip(coding=df.get_code()):
keys=[]
values1=[]
values2=[]
values=[]
dict_ip_str=''
for n in range(1,11):
with open(f'ip{n}.txt',encoding=coding) as f:
for each_line in f:
each_line=each_line.strip()
if each_line.startswith('<td data-title="IP">'):
each_line=each_line.removeprefix('<td data-title="IP">')
each_line=each_line.removesuffix('</td>')
values1.append(each_line)
if each_line.startswith('<td data-title="PORT">'):
each_line=each_line.removeprefix('<td data-title="PORT">')
each_line=each_line.removesuffix('</td>')
values2.append(each_line)
#keys
for n in range(len(values1)):
keys.append('http')
#values
values.append(f'{values1}:{values2}')
dict_ip_str=dict_ip_str+'{"'+f'http":"{values1}:{values2}"'+'},'
dict_ip_str=dict_ip_str.removesuffix(',')
return dict_ip_str
本帖最后由 nahongyan1997 于 2021-6-20 20:13 编辑
你这是包里套包啊,可别这么写。
如果你非要这么干的话私信我我告诉你办法,但是这么写我是绝壁不推荐,太乱了。
页:
[1]