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('\n')
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('\n')
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('\n')
if __name__ == "__main__":
writeData()
列表中的字典数据写入到csv表
最新推荐文章于 2024-09-28 17:00:00 发布