简体   繁体   中英

Reading .dat file using Python

Currently, I am trying to extract data in OPPORTUNITY Activity Recognition Data Set by using Python.

There is a download link for it because I can not add the file in Stackoverflow. The file can be opened in Matlab with complicated structure therefore I am still struggling with extracting it.

But the file that I want to extract data is S1-ADL1.dat located in 'dataset' folder in the link above.

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.

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() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM