我收到了一个错误:AttributeError: module 'app.parse' has no attribute 'sheet4'
。
在 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)
data_rate_savedata.py 中的
from . import parse
def data_rate_save():
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'])
main_save.py 中的
from app.parse import DataRate
#parse
DataRate()
#save
data_rate_save()
当我运行main_save.py时,会发生错误。我真的不明白为什么会发生这个错误,因为我在data_rate_savedata.py中导入了parse.py,所以我可以访问parse.py中的#4; sheet4'在data_rate_savedata.py中。我应该在main_save.py中写一些东西吗?我该如何解决这个错误? 在 models.py
中class User(models.Model):
trunsaction_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
regist_date = models.DateTimeField(auto_now=True)
user_id = models.CharField(max_length=200,null=True)
name = models.CharField(max_length=200,null=True)
age = models.CharField(max_length=200,null=True)
完全追溯
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/app/data_rate_savedata.py", line 11, in <module>
data_rate_save()
File "/Users/app/data_rate_savedata.py", line 19, in data_rate_save
for row_index in range(0, sheet4.nrows):
AttributeError: module 'app.parse' has no attribute 'sheet4'
答案 0 :(得分:0)
data_rate_savedata.py
中,请尝试:
from .parse import DataRate
# and use
# DataRate.sheet4
我猜sheet4
是DataRate的一个属性,而不是解析。