idno, name, position 및 salary와 같은 다양한 세부 사항을 가진 n 사용자 입력에 대한 직원 데이터베이스를 만들었습니다. 직원 데이터베이스는 파이썬에서 완벽하게 작동하지만 난 때 여기사용자 입력을위한 dict의 dict
내 코드입니다 CSV로 작성 :
이import csv
d={}
d1={}
n=int(raw_input("Enter the number of employees :"))
for i in range(n):
emp_name=raw_input("Enter the name of employee :")
emp_idno=raw_input("Enter the idno of employee :")
emp_position=raw_input("Enter the position of employee :")
emp_salary=int(raw_input("Enter the salary of employee :"))
d1={emp_idno: {"Name": emp_name, "Position":emp_position, "Salary":emp_salary}}
d.update(d1)
print d
for key,value in d.iteritems():
print key,value
with open('12file1.csv','w') as f:
w = csv.writer(f)
w.writerow(['Idno','Name','Position', 'Salary'])
w.writerows(d.iteritems())
with open('12file1.csv','w') as f:
w = csv.writer(f)
w.writerow(['Idno','Name','Position', 'Salary'])
for keys, values in d.iteritems():
w.writerows({'Idno':key,'Name':value['Name'],'Position':value["Position"], 'Salary':value["Salary"]})
가 딕셔너리의 내 DICT 내가하려고 해요
{idno: {name,position,salary}}
과 같아야합니다 dict의 dict을 반복 한 다음 csv에 기록합니다. csv로 중첩 된 dict을 작성하는 더 쉬운 방법을 얻을 수 있다면 좋을 것입니다. 루프에 사용
내 CSV 출력해야
Idno Name Position Salary
101 Abc Trainee 12000
102 Def Fresher 8000
코드에서 잘못된 결과가 나옵니까? 나에게 잘 어울린다. – jknupp