Hello,
my test application uses a styled text control.
When creating a new control and typing text into it, the eol is CRLF - ok
But when using file dialog to open an existing file the eol is LF. ??
The code in question:
fid = open(path, ‘rt’)
text = fid.read()
fid.close()
_stc.setText(text)
``
I triple checked that the file has 0x0A 0x0D as eol chars using hexeditor.
When doing debugging like
if text.find(’\r\n’):
print ‘windows eol’
``
I see that text has the correct (on windows) eol.
I even created a file containing just one line and eol char to test but still, stc shows LF
What am I missing here?
Thank you
Hubert
Yes, that’s what you asked it to do. When you open a file in ‘t’
mode on Windows, that means “convert all of the \r\n combinations in
the file to \n in the strings you give me”. And, if you write to a
‘t’ file, it does the opposite conversion.
If you want the characters literally as they are in the file, use
‘rb’.
You mean 0x0D 0x0A.
···
Hubert Mayr wrote:
my test application uses a styled text control.
When creating a new control and typing text into it, the
eol is CRLF - ok
But when using file dialog to open an existing file the eol
is LF. ??
The code in question:
fid = open(path, ‘rt’)
text = fid.read()
fid.close()
_stc.setText(text)
``
I triple checked that the file has 0x0A 0x0D as eol chars
using hexeditor.
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
Thank you very much
reading binary solved the issue.
I was totally focused on styled text control being the cause to forget
to check if my open syntax is the culprit. At the end it is logical that it
must have been the open call as the “normal” text editing was working.
Another thing learned and yes, you are correct I meant 0x0D 0x0A.
Thank you
Hubert
···
On Tuesday, June 28, 2016 at 3:28:06 AM UTC+2, Tim Roberts wrote:
Hubert Mayr wrote:
my test application uses a styled text control.
When creating a new control and typing text into it, the
eol is CRLF - ok
But when using file dialog to open an existing file the eol
is LF. ??
The code in question:
fid = open(path, ‘rt’)
text = fid.read()
fid.close()
_stc.setText(text)
``
Yes, that's what you asked it to do. When you open a file in 't'
mode on Windows, that means “convert all of the \r\n combinations in
the file to \n in the strings you give me”. And, if you write to a
‘t’ file, it does the opposite conversion.
If you want the characters literally as they are in the file, use
‘rb’.
I triple checked that the file has 0x0A 0x0D as eol chars
using hexeditor.
You mean 0x0D 0x0A.
-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.