[Tutor] Read and write from file
isrgish at fastem.com
Thu Aug 26 04:58:46 CEST 2004
>What I really want to do is to read the first line, 1, then replace that
>with something else, or remove it. Then read 2, and remove it, then read 3
>and change it and so forth. How can I read, write and modify at the same
>time? So far I have only been able to either read or write, but not both.
To do both you need to add a '+' to the mode ('r+' or 'w+'). If you do 'w+' it truncates the file to 0.
All the best,
>Thanks in advance....
>This email has been scanned for viruses & spam by Decna as - www.decna.no
>Denne E-post er sjekket for virus & spam av Decna as - www.decna.no
>Tutor maillist - Tutor at python.org
More information about the Tutor