标签:close one com https 复制 字符 操作 image with open
with 读取文件内容
# 第一种: # 1. 打开文件 one_file = open("test1.txt", encoding="utf-8") # 2. 读写操作 # 使用read方法, 会将文件中的所有内容读取出来, 以字符串类型呈现 content = one_file.read() print(content) # 打印读取的内容 # 3. 关闭文件 one_file.close() # 第二种:with 会自动关闭文件 with open("test1.txt", encoding="utf-8") as b: content = b.read() print(content)
with 可以进行复制文件,逗号隔开
with open("keyou_2019-07-03_21-54-52.png", mode="rb") as one_file, open("keyou.png", mode="wb") as two_file: # 2. 读写操作 content = one_file.read() # 读取第一个图片二进制数据 two_file.write(content) # 将读取的二进制数据, 写入到第二个文件中
*******请大家尊重原创,如要转载,请注明出处:转载自:https://www.cnblogs.com/shouhu/,谢谢!!*******
标签:close one com https 复制 字符 操作 image with open
原文地址:https://www.cnblogs.com/shouhu/p/12741242.html