How to read txt data in Python?
To read txt data, you can utilize the built-in functions open() and read() in Python.
# 打开文件
file = open('data.txt', 'r')
# 读取文件内容
content = file.read()
# 关闭文件
file.close()
# 输出内容
print(content)
The code above opens a file named data.txt and stores its content in a variable called content. Finally, the content is printed using the print() function.