学习笔记(19):21天通关Python(仅视频课)-文件指针与写文件
2020-06-28 08:21:56 来源:易采站长站 作者:易采站长站整理
立即学习:https://edu.csdn.net/course/play/24797/282199?utm_source=blogtoedu
import os# #文件指针
# with open('test46.py','ab',True) as f:
# print(f.tell())
# '''
# seek(self,offset,whence)
# offset:移动位数,整数是往后移,复数 往前移
# whence:0,1,2 三个参数
# 0:从开头开始
# 1:从当前位置开始
# 2:从结尾开始
# '''
# f.seek(5)
# print(f.tell())
# #一个参数,从0开始移动N位
# f.seek(10)
# print(f.tell())
# #两个参数,从当前位置移动N个位置
# f.seek(-10,2)
# print(f.tell())
# f.seek(-5,1)
# print(f.tell())
#
# #获取文件的大小
# print(os.path.getsize('test46.py'))
with open('test46.txt', 'ab', True) as f:
f.write(('hello world' + os.linesep).encode('utf-8'))
f.writelines((('hi you' + os.linesep).encode('utf-8'),
('hi me ' + os.linesep).encode('utf-8')
))
作者:Hello-Rock













闽公网安备 35020302000061号