[wingide-users] Confused about OS Commands tool box display of unicode data.

Barry Mossman BarryMossman at primos.com.au
Tue Mar 20 00:05:00 MDT 2012


> 
> You probably need to change the I/O Encoding field in the OS Command's
> definition. You should also have a Debugger > I/O > OS Commands Encoding
> preference (third one on that prefs page).
>

Thanks for your response.

I now see the OS Command Property UI setting for I/O Encoding . Thanks,
however I still can't get a fix using this.

My print statement still gives unexpected results with Unicode data when run
within Wing's OS Commands facility.

The print statements were just for debugging purposes. The issue did cause
me some confusion, but I now know about it, so I am past that now. However
perhaps you see it as a problem that Wing's OS Commands facility gives
different and unexpected results to both a debug session, and to the program
being run outside Wing in the Windows Command Prompt, when each of these
sessions are running with default options set? ... Further I can't seem to
resolve the difference with the UI's 'I/O Encoding' controls provided.

When the program (see below) is run in Wing's OS Commands window I get an
exception. (with the OS Command Property setting for I/O Encoding set to
either "Use Default" or utf-8, which is how the file is encoded ... the
Preferences|Debugger|IO settings seem to make no impact either).

When the program is run via Wing's Debugger I get no exception, and the
printed output is as expected (ie. showing the "foreign" accent marks). The
preferences|Debugger|I/O settings seem to have no impact here either (ie. I
get good results with either the default (cp850) or utf-8).

When the program is run outside Wing in the Windows Command Prompt I get no
exception, and the printed characters are as expected.

Do I need to do something in the OS Command Properties' Environment tab to
get the print statement to perform as expected in an OS Commands context ?

The context of the problem is as follows:
        with codecs.open(filename=glbl.scrobble_file_path, mode='a',
encoding='utf-8') as scrobble_file:
            scrobble_file.write(record)
        with codecs.open(filename=glbl.scrobble_file_path, mode='r',
encoding='utf-8') as scrobble_file2:
            data = scrobble_file2.readline()
            print data

The exception is raised by the print statement.
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position
44: ordinal not in range(128

It only occurs when the program is run in a OS Commands context. 
I have tried with many combinations of settings, including have all three of
the Preferences|Debugger|IO, and the command's I/O Encoding, set to utf-8.





> -----Original Message-----
> From: Wingware Support [mailto:support at wingware.com]
> Sent: Monday, 19 March 2012 11:00 PM
> To: Barry Mossman
> Cc: wingide-users at wingware.com
> Subject: Re: [wingide-users] Confused about OS Commands tool box display
of
> unicode data.
> 
> Barry Mossman wrote:
> >
> > Hi I have read some data from text file encoded with utf-8 as follows:
> >
> > with codecs.open(filename='playcounts.txt', mode='r',
> > encoding='utf-8') as scrobble_file:
> >
> > data = scrobble_file.readline()
> >
> > I then print the data with a print statement.
> >
> > If I do this in the debugger, or run the program externally outside
> > the IDE, the displayed output is as expected.
> >
> > If I run the program using the OS Comands tool box the print statement
> > fails with "'ascii' codec can't encode character u'\xe1' in position
> > 6: ordinal not in range(128)"
> >
> > Is there something I need to configure with regard to the OS Commands
> > toolbox.
> >
> 
> You probably need to change the I/O Encoding field in the OS Command's
> definition. You should also have a Debugger > I/O > OS Commands Encoding
> preference (third one on that prefs page).
> 
> --
> 
> Stephan Deibel
> Wingware | Python IDE
> Advancing Software Development
> 
> www.wingware.com



More information about the wingide-users mailing list