Why does seek return None in python?

python, seek

Solution

You are reading the wrong documentation. You need to look at `file.seek()` when using Python 2:

There is no return value.

Using `io.open()` is fine, and if you do, you'll get a different object, whose `seek()` method does return the current position:

Python 2.7.6 (default, Apr 28 2014, 17:17:35) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> f = io.open('data.json')
>>> f.seek(0, 2)
39L
>>> type(f)
<type '_io.TextIOWrapper'>
>>> f = open('data.json')
>>> f.seek(0, 2)
>>> type(f)
<type 'file'>

The `io` module is the new I/O architecture for Python 3, available in Python 2 as well. The Python 3 built-in `open()` function is an alias for `io.open()`, but not yet so in Python 2.

Problem

The doc clearly says: Return the new absolute position. However, `seek` appears to return `None` (same behavior also on Linux): ``` Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> >>> import os >>> f=open("......","r") >>> f.readline() '......\n' >>> f.tell() 44 >>> f.seek(0,2) >>> f.tell() 9636 ``` - Is this a know bug? - Is this a doc or implementation bug?

Original source