我正在寻找一种python解决方案来转换输入文件并将其原样读取为用PYTHON3编写的程序。
我的输入文件包含以下数据:
{ "h" : ["a","c","e"],
"d" : ["d", "a","g"],
"e" : ["f", "a", "b", "c"],
"b" : ["d","c"],
"c" : ["g", "c","a"],
"g" : ["w","x","y"]
}
我尝试了以下
a)datafile = open("infile.txt","r").read()
错误消息:TypeError:字符串索引必须为整数
b)datafile = open("infile.txt","r").readline()
错误消息:TypeError:字符串索引必须是整数
c)datafile = open("infile.txt","r").readlines()
错误消息:TypeError:列表索引必须是整数或切片,而不是str
顺便说一句,我是Python的新手。
临摹微笑
米琪卡哇伊
相关分类