Modify one character in a string

Scott David Daniels scott.daniels at acm.org
Fri May 26 18:22:46 EDT 2006


Marc 'BlackJack' Rintsch wrote:
> In <roy-F85321.10044225052006 at reader1.panix.com>, Roy Smith wrote:
> 
>>> Also, how do I do this when dealing with a file ; which file mode
>>> should I use and what function should I use to modify a single
>>> character once in that file mode?
>> This is a much more complicated question, because it depends on the details 
>> of the operating system you're using.  On Unix, you can seek to a specific 
>> place in a file, write a single character, seek to EOF, and you've done an 
>> in-place single character edit of the file.
> 
> Why seeking to EOF after writing the byte?

Because some operating systems may create an EOF (thus truncating the
file) after a write, close sequence.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list