with open('D:\\英文文献网址.txt') as file_object:
contents = file_object.read()
print(contents)
读取全部的text文件内容。
with open('D:\\英文文献网址.txt') as file_object:
contents = file_object.read()
for line in contents :
print(line.rstrip())
每个字按行读取
filename = 'D:\\英文文献网址.txt'
with open(filename, 'w') as file_object:
file_object.write(str('1,2,3\n'))
file_object.write('I like basketball.\n')
在文件中写入了两行,\n 是换行的意思
读取文件与写入文件时候一般都用的绝对路径