How to read file data into a list in Python?
You can use the `readlines()` method in Python to read data from a file line by line into a list.
The following is an example code:
# 打开文件
file = open('data.txt', 'r')
# 逐行读取文件数据并存入列表
data = file.readlines()
# 关闭文件
file.close()
# 打印列表数据
print(data)
In the above code, data.txt is the file name to be read. The readlines() method reads each line of data from the file into a list called data. Finally, the data in the list is printed using the print() function.
Note: The readlines() method will include the newline characters at the end of each line in the list. If you do not need these newline characters, you can use the strip() method to remove them, for example: data = [line.strip() for line in data].