查找函数Python

2024-09-28 22:42:00 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用seek函数时,我无法将whence参数设置为1。经过一些搜索,我发现我需要包含一个“类似字节的对象”,这样我就可以将whence参数设置为1。这意味着什么?我是否总是需要一个类似字节的对象,以便将whence设置为1,并使偏移量从文件中的当前索引位置开始


Tags: 对象函数字节seek偏移量参数设置whence
1条回答
网友
1楼 · 发布于 2024-09-28 22:42:00

在文本模式下open文件时,它返回的类似文件的对象是^{}(派生自^{})。他们关于{}的{a3}工作如下:

The default value for whence is SEEK_SET.

SEEK_SET or 0: seek from the start of the stream (the default); offset must either be a number returned by TextIOBase.tell(), or zero. Any other offset value produces undefined behaviour.

SEEK_CUR or 1: “seek” to the current position; offset must be zero, which is a no-operation (all other values are unsupported).

SEEK_END or 2: seek to the end of the stream; offset must be zero (all other values are unsupported).

也就是说,您只能使用whence12offset

相关问题 更多 >