在 python 中读取 .DAT 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18340457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:30:50 来源:igfitidea点击:
Reading a .DAT file in python?
提问by Michael Haywood
I am making a basic program that has a quiz with multiple choice answers. I want to access the data from the .DAT file. Here's the basic layout of the .DAT file.
我正在制作一个基本程序,其中有一个带有多项选择答案的测验。我想从 .DAT 文件访问数据。这是 .DAT 文件的基本布局。
Which sport uses the term LOVE ?
Tennis
Golf
Football
Swimming
A
How can I access each line separately?
如何分别访问每条线路?
采纳答案by mattexx
for line in open(filename, 'r'):
item = line.rstrip() # strip off newline and any other trailing whitespace
...
For the bonus: Tennis!
奖金:网球!