zoukankan      html  css  js  c++  java
  • python--文件读写

    # f = open('a.txt', 'w', encoding='utf-8')
    # names = ['a', 'b', 'c']
    # for name in names:
    # f.write(name)
    # f.writelines(names)
    # f.close()
    s = '既然青春留不住'
    f.write(s) # 效率高
    f.writelines(s) # 效率不高

    # import time


    # 进行写操作发现没有写进内容,可调用flush()
    # f = open('a.txt', 'w')
    # f.write('123')
    # f.flush() # 立即把缓冲区里面的内容写到磁盘里面
    # f.close()
    # time.sleep(50)

    # 用with可自动关闭文件,可打开多个文件用,分割
    # with open('a.txt', 'w') as f, open('b.txt', 'w') as f1:
    # f.write('666')
    # f1.write('777')

    # rb
    # wb
    # ab
    # with open('韩佳人.jpg', 'rb') as f: # 以二进制的模式打开方式
    # print(f.read())
  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/wangsilei/p/8251232.html
Copyright © 2011-2022 走看看