I need to read a binary file and place the contents in an editor created with wx.stc.StyledTextCtrl.
I used these bit of code but run my application crash:
bu = open(link,‘rb’)
for line in bu.xreadlines():
self.notebook.nameLbl.AddTextUTF8(line)
Somebody help me?
···
–
Fabio Spadaro
www.fabiospadaro.com
You probably do not *need* to read your file in a binary mode
and most probably you are suffering from the the "coding of
characters desease". 
- Read your file correctly, the Python modules io or codecs may help.
Btw, xreadlines is obsolete since ... ???
- Ensure you know the coding of what you have read.
- If necessary, decode or encode in a suitable form/coding (*).
- Use one the methods of the stc that corresponds to what you have
done (*) and populate the stc with it.
- Ensure the eol of what you have read (if included) matches the
eol configuration, you have setup for the stc widget.
There are many different ways to do the task.
jmf
···
On 8 déc, 11:48, Fabio Spadaro <fabiolinos...@gmail.com> wrote:
I need to read a binary file and place the contents in an editor created
with wx.stc.StyledTextCtrl.
I used these bit of code but run my application crash:
bu = open(link,'rb')
for line in bu.xreadlines():
self.notebook.nameLbl.AddTextUTF8(line)
Somebody help me?
--
Fabio Spadaro wrote:
I need
to read a binary file and place the contents in an editor created
with wx.stc.StyledTextCtrl.
What do you mean by "binary file", exactly? (That phrase means
different things to different people.) You can’t, for example, load
up an executable and hope the StyledTextCtrl will handle it.
Arbitrary binary files almost certainly contain characters that are
not valid UTF-8 sequences.
···
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
exactly -- if your data is utf-8, then I suggest you use JM's suggestion. If you want to be able to look at arbitrary binary data, then you don't load it into STC as utf-8.
The Peppy editor (http://peppy.flipturn.org/) has a hexedit mode for binary files -- you may want to see what Rob did with that.
NOTE: this is still a bug in STC -- it shouldn't crash in teh face of bad input -- it should raise an error, or display garbage. So may be worth a bug report.
-Chris
···
On 12/8/11 10:17 AM, Tim Roberts wrote:
I need to read a binary file and place the contents in an editor
created with wx.stc.StyledTextCtrl.
What do you mean by "binary file", exactly? (That phrase means different
things to different people.) You can't, for example, load up an
executable and hope the StyledTextCtrl will handle it. Arbitrary binary
files almost certainly contain characters that are not valid UTF-8
sequences.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov