【发布时间】:2018-02-22 23:01:58
【问题描述】:
我遇到了一个错误,
ImportError: No module named 'parse' .
在parse.py我写了
class DataRate():
data_rate ={}
data_rate =defaultdict(dict)
def try_to_int(arg):
try:
return int(arg)
except:
return arg
book4 = xlrd.open_workbook('./data/excel1.xlsx')
sheet4 = book4.sheet_by_index(0)
tag_list = sheet4.row_values(0)
for row_index in range(0, sheet4.nrows):
row = sheet4.row_values(row_index)
row = list(map(try_to_int, row))
value = dict(zip(tag_list, row))
closing_rate_dict[value['ID']].update(value)
user = User.objects.filter(corporation_id=closing_rate_dict[value['ID']]['NAME'])
我想在 data_rate_savedata.py 中使用 DataRate 类,所以我写了
import parse
def data_rate_save():
if user2:
if parse.closing_rate_dict[parse.value['ID']]['NAME'] == 'A':
parse.user2.update(data_rate_under_500 = parse.closing_rate_dict[parse.value['ID']]['d500'],
data_rate_under_700 = parse.closing_rate_dict[parse.value['ID']]['d700'],
data_rate_upper_700 = parse.closing_rate_dict[parse.value['ID']]['u700'])
我想在 main_save.py 中使用 parse.py 和 data_rate_savedata.py,所以我写了
from app.parse import DataRate
#parse
DataRate()
#save
data_rate_save()
当我运行 main_save.py 时,出现错误 导入错误:
No module named 'parse',traceback says
File "/Users/app/data_rate_savedata.py", line 1, in <module>
import parse
错了。是IDE问题?还是我写代码错了?如何解决这个错误?
【问题讨论】: