首页 > 代码库 > 列表转换成文件
列表转换成文件
f = open("Information.txt","w+",encoding="utf8") Information = [["1","alex","IT"],["2","bob","IT"]] User_Choice = int(input("Your choice is:")) for i in Information: if User_Choice == int(i[0]): Information.remove(Information[User_Choice]) for j in Information: f.write(‘,‘.join(j).strip()) #关键是这一步,把列表通过join方法转换成字符串,然后再写入文件 f.close()
该程序的作用是用户输入数字后,会删掉列表中对应的元素,然后再把列表中剩余的元素写入文件中
列表转换成文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。