Python内置了文件读写的函数open,read 用法示例: open('/home/root/files.txt ') 在打开文件后,操作完成后可以使用close()关闭文件,但比较好的文件读写方法是使用 with open('files.txt') as file_object: #something file=file_object.read() print(file.rstrip()) 如此,在操作结束后,with便会把文件关闭,无需close 注意:使用read读取文件时,在末尾会添…