When writing text. . .

Gerhard Fiedler gelists at gmail.com
Fri Jul 14 21:19:31 EDT 2006


On 2006-07-14 18:05:56, Ivan Shevanski wrote:

> Hey I'm pretty new to python and I have a question.  I'm trying to write:
> "[BOOT]
> run=C:\windows\aawin.bat"
> 
> in my win.ini
> So I went about it like this:
> 
> win = open('C:\windows\win.ini', 'a')
> win.write('[BOOT]')
> win.write('\n')
> win.write('run=C:\windows\aawin.bat')

Maybe write a '\n' before the [BOOT] -- unless you can guarantee that the
previous line ends with a CRLF.

BTW, it's probably a good thing to always escape the backslash (that is,
use '\\') when you want a backslash, not only for the '\\a' case. Or of
course use a raw string.

Gerhard




More information about the Python-list mailing list