I got an error: AttributeError: module 'app.parse' has no attribute 'sheet4'
.
In parse.py I wrote
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)
in 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'])
in main_save.py
from app.parse import DataRate
#parse
DataRate()
#save
data_rate_save()
When I run main_save.py, the error occurrs. I really cannot understand why this error happens because I import parse.py in data_rate_savedata.py, so I can access parse.py of 'sheet4' in data_rate_savedata.py. Should I write something in main_save.py? How can I fix this error? in 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)
Full traceback is
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'