Message27200
Logged In: YES
user_id=31435
This is actually pilot error (not a bug!), although it's
subtle: Python uses the platform C I/O implementation, and
in standard C mixing reads with writes yields undefined
behavior unless a file-positioning operation (typically a
seek()) occurs between switching from reading to writing (or
vice versa); here from the C standard:
When a file is opened with update mode (’+’ as the
second or third character in the above list of mode
argument values), both input and output may be
performed on the associated stream. However, output
shall not be directly followed by input without an
intervening call to the fflush function or to a file
positioning function (fseek, fsetpos, or rewind), and
input shall not be directly followed by output
without an intervening call to a file positioning
function, unless the input operation encounters
end-of-file.
In other words, the result of running your sample code is
undefined: nothing is guaranteed about its behavior, which
both can and does vary across platforms.
If you want defined behavior, then, for example, add
>>> f.seek(0)
between your write() and read() calls. |
|
Date |
User |
Action |
Args |
2007-08-23 14:37:03 | admin | link | issue1394612 messages |
2007-08-23 14:37:03 | admin | create | |
|