在python中打开文件进行读取很容易:
f = open('example.txt', 'r')要获取文件中的所有内容,只需使用read()
file_contents = f.read()
并打印内容,只需执行以下操作:
print (file_contents)
完成后,别忘了关闭文件。
f.close()

在python中打开文件进行读取很容易:
f = open('example.txt', 'r')要获取文件中的所有内容,只需使用read()
file_contents = f.read()
并打印内容,只需执行以下操作:
print (file_contents)
完成后,别忘了关闭文件。
f.close()