Explane File modes please --

pxlpluker pxlpluker at cfl.rr.com
Wed Mar 10 05:15:10 CET 2004

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/20040309/c741afd9/attachment.html>

More information about the Python-list mailing list