首页 > 其他 > 详细

文件相关操作

时间:2018-09-01 14:54:49      阅读:177      评论:0      收藏:0      [点我收藏+]

#非文字类文件,用rb,上传下载都是二进制,utf-8,gbk形式rb
# f = open(‘f:\\123.txt‘, mode="rb",)
# content = f.read()
# f.write("you ae".encode("utf-8"))
# print(content)
# print(f)
# f.close()

#bypes ---------> str R

# f = open("123", mode="r", encoding="utf-8")
#
# content = f.read()
#
# print(content,type(content))
# print(f,type(f))
# f.close()

#W----> no file-->build have file-->first delete all content and then write

# f = open("log", mode="w", encoding="utf-8")
# f.write("can you understand")
# f.close()
# WB

# f = open("log", mode="wb")
# f.write("123".encode("utf-8"))
# f.close()

#add --->append()
# f = open("log", mode="a", encoding="utf-8")
# f.write("you are so beautiful")
#
# f.close()
# ab---->btype
# f = open("log", mode="ab")
# f.write("i think you are ".encode("utf-8"))
# f.close()

#read and write
# f = open("log",mode="r+", encoding="utf-8")
# print(f.read())
# f.write("you are so lovely")
#
# f.close()
#r + b
# f = open("log",mode="r+b")
# print(f.read())
# f.write("you are so lovely".encode("utf-8"))
#
# f.close()
#write and read
# f = open("log",mode="r+", encoding="utf-8")
# f.write("aaazzzzzzzzzz")
# print(f.read())
# f.close()
#change the mouse position
# f.seek(0)#begin


# f = open("log", mode="r+", encoding="utf-8")
# f.seek(3)#按照字节找,,,一个中文三个字节
# print(f.tell())#告诉光标的位置

# content = f.read()
# print(content)
# f.close()

文件相关操作

原文:https://www.cnblogs.com/jly1/p/9570290.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!