【发布时间】:2013-03-29 15:40:40
【问题描述】:
with open('rules_test1Fold0w4_sample00ll1.dat') as fileobj:
lines = list(fileobj)
actualrules=''
for index in sortrule:
print lines[index]
我有这段代码可以打印出 .dat 文件的某些行,但是我想要做的是让每一行成为数组中的一个元素。 例如,如果我的文件在
中有这个`'Once upon a time there was a young
chap of the name of Peter he had a
great friend called Claus'`
数组将是[Once upon a time there was a young,chap of the name of Peter he had a,great friend called Claus]
【问题讨论】:
-
您发布的代码符合您的要求。你有问题吗?
-
我猜你回答了自己的问题
-
它打印出行,它不把它放入一个数组中
-
是的,它确实将它们放在一个数组中。它将它们放入
lines。 -
或者,您是否只想将
sortrule选择的行放入数组中?