zoukankan      html  css  js  c++  java
  • 文件相关操作


    #非文字类文件,用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()

  • 相关阅读:
    Lua函数
    Lua 造成的代码冗余太严重了, 这个现状怎么改善?
    Lua 造成的代码冗余太严重了, 这个现状怎么改善?
    Lua 错误处理方法
    Lua 错误处理方法
    C++引用、指针的选择
    C++引用、指针的选择
    Windows 7下VS2008升级补丁
    Windows 7下VS2008升级补丁
    天龙八部服务器端共享内存的设计(3/3)
  • 原文地址:https://www.cnblogs.com/jly1/p/9570290.html
Copyright © 2011-2022 走看看