我想写一个二维数组到一个python3txt文件
例如
My_list = ['Hello', 'World', 0], ['Pretty', 'World', 1], ['Tired', 'World', 2]]
进入myu text.txt
我已经尝试了很多方法,但没有一种是我可以推荐的,因为我得到了各种各样的结果,包括1个元素列表:
["['Hello', 'World', 0], ['Pretty', 'World', 1], ['Tired', 'World', 2]"]
和字符串列表:
["[Hello', 'World', 0]", "['Pretty', 'World', 1]", "['Tired', 'World', 2]"]
以及其他精彩的结果。 有人知道一些简单明了的代码吗? 只是出于好奇,我很努力
我想能够读出我的清单从文件中再次和充分利用它作为一个清单再次
e、 g,print(my_list[0][0])
产生'Hello'
嗨,有兴趣的人
我想将一个数组保存到一个Python文本文件中并完全检索它,这样就可以处理所有元素
我坚持我的问题,并解决了什么是非常混乱的代码,我敢肯定
下面的代码就是我想做的
毫无意义的运动,但我不得不这么做
谢谢你的帮助和想法
同时考虑yaml。需要安装pyyaml(
pip install pyyaml
)将列表对象保存到文件:
输出文件如下所示:
要加载列表:
要直接处理字符串,可以使用标准库^{
而不是基本的读/写:
json
擅长序列化列表/目录/数字/字符串:结果:
相关问题 更多 >
编程相关推荐