(Python) Creating a list of labeled text file data

Asked 2 years ago, Updated 2 years ago, 115 views

Text file content is
1 0.552344 0.384028 0.159375 0.195833
1 0.780078 0.595833 0.236719 0.133333

It's like this After executing Python code [1 0.552344 0.384028 0.159375 0.195833] , [1 0.780078 0.595833 0.236719 0.133333] I want to print it out as a list. What should I do? ㅠ<

python list data

2022-09-21 18:59

1 Answers

You can use the readlines function to read the contents of the file in the form of a list in line units.

file = open("something.txt", "r")
lines = file.readlines()

print(lines)


2022-09-21 18:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.