[Tutor] adding more text to a file

wesley chun wescpy at gmail.com
Mon Jan 18 09:09:14 CET 2010


On Sun, Jan 17, 2010 at 5:19 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Magnus Kriel" <magnus.kriel at gmail.com> wrote
>
>> It might be that when you create a file for the first time with 'a', that
>> it
>> will through an exception. So you will have to try with 'w', and if there
>> is
>> an exception, you know the file does not exist and you will have to create
>> the file for the first time with 'w'.
>
> That should not happen. If there is no file 'a' will act like 'w'


alan is correct. with 'a', if a file doesn't exist, it will create it
and open it for write. if it does exist, it will go to the current EOF
and open it for write starting from that point. the only time 'a'
throws an exception is if the file cannot be opened, e.g., it's on a
network drive that isn't there, no perms on that filesystem, etc.

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
    http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list