word wrap on different OS
gerhard at bigfoot.de
Mon Jun 3 13:09:09 CEST 2002
* Sabine Richter <sabine at textraeume.de> [2002-06-03 12:48 +0200]:
> I am not sure if I think clear on this subject:
> A simple text file has been created for example on MS Dos or MacOS. So
> the sign for a word wrap will be "\r\n" on MS Dos or "\r" on MacOS.
> Then I save the file on a windows file system. The sign for the word
> wrap will be converted to "\n".
Normally, you want to process the file line by line. Is this the case for you,
too? Then, you can use the following pattern:
f = open("foo")
for line in f.xreadlines():
# Get rid of any trailing whitespace, including CR and LF characters
line = line.rstrip()
# do something with the line now
There is no need to read the whole file and split it at line endings, the
readlines() and xreadlines() methods of file objects are invented just for
> And next question:
> If I write a script, which uses MyODBC and the odbc-module from win32
> extensions to connect to a MySQL-database, it can only be used on
> windows. Isn't it?
Yes. I already recommended the MySQLdb module to you, which will work fine on
Windows and Unix. If you can spare a few euros, you can get a commercial
license for mxODBC. This is an ODBC solution that will also work on Unixen. If
you target MySQL only, MySQLdb is the way to go. Everything else is
superfluous, and doesn't have any technical advantages.
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list