Search code examples
built-inpythonpython-docx

Python doc help(f.seek)


i have python shell. Python -V is 3.3.2

>>>f = open('data.txt', 'r')
>>>dir(f)
[..."it's ok"...]
>>>help(f.seek)
Help on built-in function seek:

seek(...)

Why i not get info about this BIF? My python shell correctly?


Solution

  • The I/O infrastructure was overhauled in Python 3, completely replacing the old Python 2 file object with a new object hierarchy.

    When you open a file in text mode, you get an object implementing the io.TextIOBase interface, which wraps a io.BufferedIOBase object, which in turn wraps something implemting the io.RawIOBase interface; many methods on the former two are just proxies for methods on the object they wrap.

    Neither the io.TextIOBase nor the io.BufferedIOBase classes have docstrings on these various proxy methods.

    You can reach down to the raw I/O object with f.buffer.raw and get the help info on the .seek method there:

    help(f.buffer.raw.seek)
    

    You could also make a case that this is a bug; arguably the proxy methods should at least have a docstring that states that they pass on the call to their underlying object so you can find the original method. A pointer to the f.buffer attribute would be helpful, in such cases. Feel free to make that case over at the Python issue tracker.