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()

  • 相关阅读:
    MySQL主从复制的作用?
    MySQL的逻辑架构
    SQL语句的执行流程
    Count(*)在不同引擎的实现方式
    视图
    MySQL经典练习题(五)
    pyinstaller基本操作
    git基本操作
    Ubuntu安装tensorflow
    ScrollView can host only one direct child
  • 原文地址:https://www.cnblogs.com/jly1/p/9570290.html
Copyright © 2011-2022 走看看