做网站怎么制作,wordpress对接公众号源码,电商门户网站建设方案,网站wap版影响权重么open def open(file: FileDescriptorOrPath, //路径mode: OpenTextMode r, //设置打开文件的模式 r 以只读方式打开文件。文件的指针将会放在文件的开头。这是默认模式。 w 打开一个文件只用写入。如果该文件已存在则打开文件#…open def open(file: FileDescriptorOrPath, //路径mode: OpenTextMode r, //设置打开文件的模式 r 以只读方式打开文件。文件的指针将会放在文件的开头。这是默认模式。 w 打开一个文件只用写入。如果该文件已存在则打开文件并从开头编辑 原有内容会被删除。如果该文件不存在创建新文件。a 打开一个文件用于追加。如果该文件已存在新的内容将会被写入到已有内容之后。如果该文件不存在 创建新文件进行写入。buffering: int -1,encoding: str | None None, 编码格式 推荐utf-8errors: str | None None,newline: str | None None,closefd: bool True,opener: _Opener | None None,
) - TextIOWrapper
file open(./01/filedemo.py,r,encodingUTF-8)
print(type(file))
#读取部分内容
text file.read(1024)
print(text)
#读取全部内容
text file.read()
print()
file.seek(0)lines file.readlines()
print(flinestype{type(lines)} lines{lines})
print(****************************)file.seek(0)
#每次只读一行
line file.readline()
print(flinetype{type(line)} line{line})#关闭 close()
file.close()print()
print()#
with open(./01/filedemo.py,r,encodingUTF-8) as file:for line in file:print(ftype {type(file)} line content {line})write
#创建文件
file open(./01/hello.txt,w,encodingUTF-8)
#写入内存 注意 文件存在 会清空掉原来的内容 重新写 文件存在 直接写
file.write(hello python write)
#写入磁盘
file.flush()
#close 里面有调用 flush
file.close() append
#创建文件
file open(./01/hello.txt,a,encodingUTF-8)
#写入内存 注意 文件存在 会清空掉原来的内容 重新写 文件存在 直接写
file.write(hello world hello python)
#写入磁盘
file.flush()
#close 里面有调用 flush
file.close()