我在python中有一些数据作为数组,如下所示:
train = [("Great place to be when you are in Bangalore.", "pos"),
("The place was being renovated when I visited so the seating was limited.", "neg"),
("Loved the ambience, loved the food", "pos"),
("The food is delicious but not over the top.", "neg"),
("Service - Little slow, probably because too many people.", "neg"),
("The place is not easy to locate", "neg"),
("Mushroom fried rice was spicy", "pos"),
("Cocee was hot and spicy", "neg")
]
我想从文件中读取这些数据。所以我创建了一个文本文件并将数据复制到其中
现在,当我使用以下代码读取文本文件时:
train = []
text_file = open("testdata.txt", "r")
train = text_file.readlines()
text_file.close()
train
在文本文档中每行有8个项目。我希望它与我在python代码中给出的数据相同。请帮忙。刚才提到的问题没有回答我的问题
使用json库
这应该会有帮助。使用
ast
模块输出:
相关问题 更多 >
编程相关推荐