[sapug] linux/win difference
Garry Trethewey
garrytre at bigpond.com
Thu Feb 2 01:33:33 CET 2012
On 01/02/12 18:34, Garry Trethewey wrote:
<stuff deleted>
>
> this code:-
>
> LF_CR = chr(13) + chr(10)
> oldStrWin = '</trkseg>' + LF_CR + '<trkseg>'
> newStrWin = '</trkseg>' + LF_CR + '</trk>' + LF_CR *2 + '<trk>' + LF_CR
> + '<trkseg>'
> outStr = inStr.replace(oldStrWin, newStrWin)
>
> - works as I'd expect in linux, but in Win Vista or Win 7 it doesn't.
>
> So result in win vista & 7 :-
> </trkseg>
> <trkseg>
>
> Results in linux :-
> </trkseg>
> </trk>
>
> <trk>
> <trkseg>
<stuff deleted>
Thanks both for that.
New code works :-
if osName == 'posix':
NL = chr(13) + chr(10)
if osName == 'nt':
NL = '\n' # or chr(10)
# d'oh!
# Had lots of trouble with win CR_LF **not** being CR_LF
# see emails
# Tim Wegener linux/20120201-2155
# Daryl Tester linux/20120201_2050
# for more options
oldStrWin = '</trkseg>' + NL + '<trkseg>'
newStrWin = '</trkseg>' + NL + '</trk>' + NL *2 + '<trk>' + NL + '<trkseg>'
outStr = inStr.replace(oldStrWin, newStrWin)
"It" (is that win or python?) converts chr(13) + chr(10) to chr(10) ie
\n as it reads, then converts back to chr(13) + chr(10) as it writes. So
without "print repr(inStr)" I'd never have seen the prob.
Yep, file opened in text mode. inFile = open(inFileName, "r")
The discussion of all the opening modes is something I never thought I'd
have a use for, only ever using txt files. But now I'm moving into
windows, I'll keep it for probs I never had before.
Thanks again
------------------------------------
Garry Trethewey
------------------------------------
More information about the sapug
mailing list