python文件seek_Python文件读取中:f.seek(0)和f.seek(0,0)有什么区别?

这篇博客详细解释了Python中file对象的seek方法,尤其是offset和whence参数的用法。通过示例展示了whence取不同值时如何影响文件指针移动,包括从文件开头、当前位置和文件末尾开始的移动。讨论了seek(0)和seek(0,0)在默认情况下没有区别,但强调了whence的其他设置可能导致不同的行为。" 127398862,7981638,北大软件工程mooc:敏捷开发方法详解与习题解析,"['软件工程', '敏捷流程', '敏捷开发', '极限编程', 'Scrum']
摘要由CSDN通过智能技术生成

2016-06-06 回答

你好!

>>> print f.seek.__doc__

seek(offset[, whence]) -> None. Move to new file position.

Argument offset is a byte count. Optional argument whence defaults to

0 (offset from start of file, offset should be >= 0); other values are 1

(move relative to current position, positive or negative), and 2 (move

relative to end of file, usually negative, although many platforms allow

seeking beyond the end of a file). If the file is opened in text mode,

only offsets returned by tell() are legal. Use of other offsets causes

undefined behavior.

Note that not all file objects are seekable.

>>>

f.seek的参数说明如上。

仅代表个人观点,不喜勿喷,谢谢。

追问:

大哥,看不懂啊,能解释下不?

追答:

回答你的问题:

1. whence 的默认参数是0。

所以seek(0)和f.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值