[Tutor] Questions on file.read

Negroup - negroup at gmail.com
Thu Jul 14 12:26:35 CEST 2005

>>> help(f.read)

Help on built-in function read:

    read([size]) -> read at most size bytes, returned as a string.

    If the size argument is negative or omitted, read until EOF is reached.
    Notice that when in non-blocking mode, less data than what was requested
    may be returned, even if no size parameter was given.

Hi tutors.
What does "blocking-mode" mean, and how can I be sure that when
reading a file I'm not in such modality (and eventually switch)? I
need to read the whole content of a file, not just some pieces.

Another question. Python tutorial states:

"To read a file's contents, call f.read(size), which reads some
quantity of data and returns it as a string. size is an optional
numeric argument. When size is omitted or negative, the entire
contents of the file will be read and returned; it's your problem if
the file is twice as large as your machine's memory."

What does exactly mean that it's my problem (crash? an exception will
be raised? fire and flames? xyz?). How can my recognize a "too big
file" before read it?


More information about the Tutor mailing list