목록의 사전 데이터를 csv표에 쓰기

7525 단어 python 기초
def writeData():
	rows = self.info_list()	#   [{}]
	if not os.path.exists('userinfo.csv'):
	     with open('userinfo.csv','a', newline='', encoding='utf-8') as f:
	         headers = 'surname,firstName,contactPhoneNo,emailAddress,loginId,password'
	         f.writelines(headers)
	         f.writelines('
'
) f.writelines("%s,%s,%s,%s,%s,%s" % (rows[0]["surname"],rows[0]["firstName"],rows[0]["contactPhoneNo"],rows[0]["emailAddress"],rows[0]["loginId"],rows[0]["password"],)) f.writelines('
'
) else: with open('userinfo.csv', 'a', newline='', encoding='utf-8') as f: f.writelines("%s,%s,%s,%s,%s,%s" % ( rows[0]["surname"], rows[0]["firstName"], rows[0]["contactPhoneNo"], rows[0]["emailAddress"], rows[0]["loginId"], rows[0]["password"],)) f.writelines('
'
) if __name__ == "__main__": writeData()

좋은 웹페이지 즐겨찾기