python文件的读取
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python文件的读取相关的知识,希望对你有一定的参考价值。
1.新建文件
vim read.py
2.写入以下代码
file_read = open("/etc/hosts",mode="r") #以读的方式打开文件
print(file_read.read(55))
print(file_read.read(5))
print(file_read.read())
file_read.close() #关闭文件
file_read1 = open("/etc/passwd",mode="r")
print(file_read1.read(100))
file_read1.close()
file_read2 = open("/root/day3/xixi.txt",mode=w) #以写的方式打开文件
file_read2.write("dsadsafsa\\n") #写入内容
file_read2.close() #关闭文件
以上是关于python文件的读取的主要内容,如果未能解决你的问题,请参考以下文章