zoukankan      html  css  js  c++  java
  • 文件指针偏移量


    # f.seek(offset,whence)
    #offset代表文件的指针的偏移量,单位是字节bytes
    #whence代表参考物,有三个取值
    #0:参照文件的开头
    #1:参照当前文件指针所在位置
    #2: 参照文件末尾
    #ps:快速移动到文件末尾f.seek(0,2)

    #强调:其中whence=1和whence=2只能在b模式下使用
    # f=open('c.txt',mode='rt',encoding='utf-8')
    # # f.seek(9,0)
    # print(f.tell()) # 每次统计都是从文件开头到当前指针所在位置
    # # print(f.readline())
    #
    # f.close()


    # f=open('c.txt',mode='rb')
    # f.readline()
    # f.seek(6,1)
    # print(f.readline().decode('utf-8'))
    # print(f.tell())
    # f.close()


    # f=open('c.txt',mode='rb')
    # f.seek(-9,2)
    # print(f.readline().decode('utf-8'))
    # print(f.tell())
    # f.close()

     

    # 了解(**)
    # 只有在t模式下的read(n),n代表的是字符个数,除此之外其他但凡涉及文件指针的移动都是以字节为单位的
    # f=open('c.txt',mode='rt',encoding='utf-')
    # print(f.read(3))
    # f.close()

    # f=open('c.txt',mode='rb',)
    # print(f.read(3).decode('utf-8'))
    # f.close()


    # ab a+b r+b
    f=open('b.txt',mode='at',)
    f.truncate(9) # 参照物永远是文件开头
    f.close()

     

     

  • 相关阅读:
    Div+CSS 布局
    Windows Mobile 参考:
    Linux export的作用
    CSS(2)基本语法
    HTML(6)超链接
    HTML(5)常用的格式标签
    HTML(8)表格
    CSS(1) CSS简介
    HTML(7)图像、背景和颜色
    HTML(10)框架
  • 原文地址:https://www.cnblogs.com/wangcheng9418/p/9305744.html
Copyright © 2011-2022 走看看