[英]Reading .dat file using Python
Currently, I am trying to extract data in OPPORTUNITY Activity Recognition Data Set by using Python.目前,我正在尝试使用 Python 在OPPORTUNITY Activity Recognition Data Set 中提取数据。
There is a download link for it because I can not add the file in Stackoverflow.有一个下载链接,因为我无法在 Stackoverflow 中添加文件。 The file can be opened in Matlab with complicated structure therefore I am still struggling with extracting it.该文件可以在具有复杂结构的 Matlab 中打开,因此我仍在努力提取它。
But the file that I want to extract data is S1-ADL1.dat located in 'dataset' folder in the link above.但是我要提取数据的文件是位于上面链接中“数据集”文件夹中的 S1-ADL1.dat。
Here is the content in the file: File Content这是文件中的内容:文件内容
I am using code:我正在使用代码:
with open("S1-ADL1.dat") as infile:
file_contents = infile.readlines()
print(file_contents)
but the terminal return nothing.但终端什么都不返回。
Does anyone know how to get the data please help me.有谁知道如何获取数据请帮助我。
Thank you.谢谢你。
either use a for loop with readlines()
or use read()
instead.要么使用带有readlines()
的 for 循环,要么使用read()
代替。
with open("S1-ADL1.dat") as infile:
file_contents = infile.read()
print(file_contents)
or或者
file = open('S1-ADL1.dat', 'r')
file_contents = file.readlines()
for line in file_contents:
print(line.strip())
file.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.