[Tutor] Need help appending data to a logfile

eryksun eryksun at gmail.com
Tue Jun 18 03:20:23 CEST 2013


On Mon, Jun 17, 2013 at 5:43 PM, Dave Angel <davea at davea.name> wrote:
> But in 3.3, it says:
> Help on built-in function close:
>
> close(...)
>
> with no more explanation.

The category "built-in function" here doesn't mean it's in the
builtins namespace. It means it's a function or method from an
extension module (in this case the _io module).

    >>> type(sys.stdin.close)
    <class 'builtin_function_or_method'>

    >>> inspect.isbuiltin(sys.stdin.close)
    True

As to the docstring, IOBase.close has a docstring:

    >>> print(io.IOBase.close.__doc__)
    Flush and close the IO object.

    This method has no effect if the file is already closed.

RawIOBase, BufferedIOBase, and TextIOBase inherit this method.

But the close() method for the following concrete implementations is
missing a docstring:

    TextIOWrapper
    BufferedReader
    BufferedWriter
    BufferedRandom
    BufferedRWPair

TextIOWrapper.close calls textiowrapper_close in Modules/_io/textio.c.
 The Buffered* types use buffered_close in Modules/_io/bufferedio.c.

Otherwise the other concrete implementations have docstrings.

Raw FileIO:

    >>> print(io.FileIO.close.__doc__)
    close() -> None.  Close the file.

    A closed file cannot be used for further I/O operations. close()
    may be called more than once without error. Changes the fileno
    to -1.

For example:

    >>> (sys.stdin.buffer.raw.close.__doc__ ==
    ...  io.FileIO.close.__doc__)
    True

Raw SocketIO:

    >>> print(socket.SocketIO.close.__doc__)
    Close the SocketIO object.  This doesn't close the underlying
            socket, except if all references to it have disappeared.

StringIO (in-memory TextIO):

    >>> print(io.StringIO.close.__doc__)
    Close the IO object. Attempting any further operation after the
    object is closed will raise a ValueError.

    This method has no effect if the file is already closed.

BytesIO (in-memory BufferedIO):

    >>> print(io.BytesIO.close.__doc__)
    close() -> None.  Disable all I/O operations.


More information about the Tutor mailing list