Hi Rob,
> My platform (eComStation,OS/2) uses the 0x0D0A convention for line end.
> After a reindent this has been changed to 0x0D0D0A (thus a 0x0D is added
> by jallib.py). When I reindent that output a second time the 0x0D0D0A is
> not changed anymore. I suppose the same happens under Windows.
> The extra 0x0D is no problem for JalV2, and it is also easy to remove
> from the source file, but better there would be no additional 0x0D in
> the first place.
> I thought it must be possible in a Python program to determine the
> platform on which it is running and react accordingly w.r.t. line end
> convention. I searched and found a string sys.platform which displays as
> 'os2knix' on my PC.
>
More complicated than that. Of course python can figure out which platform
it's running on, but files are being created on different platforms, so
files may embed different linefeed chars than the ones detected on the
running platform. This is for the reading part. For writing, I ask python to
use the platform linefeed chars (os.linesep). That's why \n became \r\n
(probably when Albert, running Windows, modified it, I guess).
Now you're right, there's a bug for win platform or any CRLF platform. I did
faced the exact same problem when dealing with merging board & tests files.
Too bad nobody reported it ealier...
The trick is, when writing files, not to use this code:
fout = file("file.jal","w")
print >> fout, os.linesep.join(content)
but this one:
fout = file("file.jal","wb")
fout.write(os.linesep.join(content))
(I let this explanation here, for any one interested, starting with me when
I'll face again the problem... so, the problem with the first case is it
uses "w" operator when opening files. This means ASCII format, and this
python itself will act on linefeed. It seems "print >> fout" instead of
"fout.write" also makes python deals with linefeed. So, let's be explicit,
"wb" + "fout.write" will tell python that content is binary, and that it
should shut up and let me do what I want.
Biblio:
- http://www.python.org/dev/peps/pep-0214/ , see "Justification" paragraph
explaining print will add a new line
- http://docs.python.org/tutorial/inputoutput.html : see "Reading and
Writing Files", it states "On Windows, 'b' appended to the mode opens the
file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'.
Windows makes a distinction between text and binary files; the end-of-line
characters in text files are automatically altered slightly when data is
read or written."
)
>
> I found also a 'platform' which could be useful. platform.platform()
>
> returns 'OS-2-1-i386-32bit' on my PC.
>
import os
will give all specific things about running OS.
>
> Please take this in consideration (low priority).
>
I did, rev. 1382 !
Cheers,
Seb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---