Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

The documentation you want is here, under io.TextIOBase. For some reason io.TextIOWrapper, an instance of which is returned from open, does not expose the docstrings from its superclass.


These classes are implemented in C and as such don't have the luxury afforded to Python classes of having docstrings and signatures automatically shown and propagated. Chances are nobody had wanted this enough to implement it fully for TextIOWrapper.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top