outfile = open("lxyfiledemo.txt","w")
outfile.write("hello,this is just a test for writing file in python")
outfile.write("\n")
outfile.write("hi over")
outfile.close()
infile = open("lxyfiledemo.txt")
content = infile.read()
infile.close()
print(content)
hello,this is just a test for writing file in python
hi over
['hello,this is just a test for writing file in python\n', 'hi over']
说明:以上结果可以看到,read读到全部内容然后输出。
readlines读进一个list然后打印这个list.