구문 분석을 수행하려면 & 사전을 만들고 user_id가 동일한 모델 (User)을 입력하십시오. 이제 오류가 발생했습니다 : ValueError: invalid literal for int() with base 10: '013000ab7C8'
. 물론 '013000ab7C8'은 int가 아니지만이 오류가 발생한 이유를 이해할 수 없습니다. 은 내가 USER_ID에서 사용자의 폴더 아래에 & excel1.xlsx를 엑셀 파일을 연결 싶어 ValueError : 밑이 10 인 int()에 대한 리터럴이 올바르지 않습니다. '013000ab7C8'
#coding:utf-8
from django.shortcuts import render
import xlrd
from .models import User
book = xlrd.open_workbook('../data/excel1.xlsx')
sheet = book.sheet_by_index(1)
def build_employee(employee):
if employee == 'leader':
return 'l'
if employee == 'manager':
return 'm'
if employee == 'others':
return 'o'
for row_index in range(sheet.nrows):
rows = sheet.row_values(row_index)
is_man = rows[4] != ""
emp = build_employee(rows[5])
user = User(user_id=rows[1], name_id=rows[2], name=rows[3],
age=rows[4],man=is_man,employee=emp)
user.save()
files = glob.glob('./user/*.xlsx')
data_dict_key ={}
for x in files:
if "$" not in x:
book3 = xlrd.open_workbook(x)
sheet3 = book3.sheet_by_index(0)
cells = [
]
data_dict = OrderedDict()
for key, rowy, colx in cells:
try:
data_dict[key] = sheet3.cell_value(rowy, colx)
except IndexError:
data_dict[key] = None
if data_dict['user_id'] in data_dict_key:
data_dict_key[data_dict['user_id']].update(data_dict)
continue
data_dict[data_dict_key['user_id']] = data_dict
for row_number, row_data in data_dict_key.items():
user1 = User.filter(user_id=row_data['user_id']).exists()
if user1:
user1.__dict__.update(**data_dict_key)
user1.save()
views.py
에 쓴, 각 데이터가 동일 USER_ID가있는 경우,이 연결된다는 것을 의미합니다. data_dict_key 내가이 문제를 해결하는 방법?dicts = {
'013000ab7C8: OrderedDict([
('user_id', '013000ab7C8'),
('name_id', 'Blear'),
('nationality', 'America'),
('domitory', 'A'),
('group', 1),
]),
'088009cd1W9': OrderedDict([
('user_id', '088009cd1W9'),
('name_id', 'Tom'),
('nationality': 'UK'),
('domitory': 'B'),
('group': 18),
])
}
내 코드에 어떤 문제가 있습니까? 당신의 User
모델의 user_id
필드가 IntegerField
로 지정된
코드 스택에 오류 스택 추적을 제공 할 수 있습니까? –