Explane File modes please --

Terry Reedy tjreedy at udel.edu
Wed Mar 10 11:47:10 EST 2004


Please do not post html.  It makes it harder to respond!  In particular, impossible to insert comments in the proper place.  Some newsreaders may not read at all or display incorrectly.

Truncate = clear = erase everything.
Update = move around and make changes here and there.  Cannot do this without +.
I am not sure if any diff between r+ and a+.

tjr
  "pxlpluker" <pxlpluker at cfl.rr.com> wrote in message news:404E9728.10906 at cfl.rr.com...
  What exactly does the underlined text mean. w & a obviously mean you are going to update the file. 
  So what does the + mean on w+ & a+ mean?
  Also please could someone explain w+ truncating the file.
  I may just be dense so please be patient :)
  -------------------------------------------------------------------------
  [Copy from python 2.3.3 help file]
  file( filename [, mode [, bufsize ] ] )

  Return a new file object (described earlier under Built-in Types). The first two arguments are the same as for stdio's fopen(): filename is the file name to be opened, mode indicates how the file is to be opened: 'r' for reading, 'w' for writing (truncating an existing file), and 'a' opens it for appending (which on some Unix systems means that all writes append to the end of the file, regardless of the current seek position). 

  Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files (else it is ignored). If the file cannot be opened, IOError is raised.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040310/633abc1c/attachment.html>


More information about the Python-list mailing list