1.常用格式

with open(r"文件名",r(打开方式)) as f:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

  strline=f.readline()

  while strline:

    print(strline)

    strline = f.readline()

 

with open(r"文件名",r(打开方式)) as f:

  l= list(f)

  for line in l:

    print(line)

2.文件操作

seek(offset,from) 移动指针

offset 是你需要开始读取的字节位置  (移动单位为字节)

form范围:0 表示从文件头、1 表示从当前位置、2 表示从文件末尾

tell 用来显示文件读写指针的当前位置

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄