how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Install and use the Unicode version of wxPython.

···

-----Original Message-----

From: Prashant Deshmukh

Sent: 25 Jun 2012 12:48:51 GMT

To: wxpython-users@googlegroups.com

Subject: [wxPython-users] how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Hello everyone,

I am using

python 2.6

wxPython 2.8.12.1

to get string from wx.choice box i am using following code

mystringvalue = self.panels[i].chcchoice.GetStringSelection()

it works fine if wx.choice contains only alphanumerical characters.

it;s giving error when i am using special character like µ

and in this case giving error as

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xb5’

in position 9: ordinal not in range(128)

Can anyone help to resolve this.

Thanks

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

This is problem with just one of those strings. for this just installing unicode version doesn’t seem feasible.
does this don’t have any simple solution.

···

On Monday, 25 June 2012 18:33:16 UTC+5:30, Gadget Steve wrote:

Install and use the Unicode version of wxPython.

-----Original Message-----

From: Prashant Deshmukh

Sent: 25 Jun 2012 12:48:51 GMT

To: wxpython-users@googlegroups.com

Subject: [wxPython-users] how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Hello everyone,

I am using

python 2.6

wxPython 2.8.12.1

to get string from wx.choice box i am using following code

mystringvalue = self.panels[i].chcchoice.GetStringSelection()

it works fine if wx.choice contains only alphanumerical characters.

it;s giving error when i am using special character like µ

and in this case giving error as

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xb5’

in position 9: ordinal not in range(128)

Can anyone help to resolve this.

Thanks

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

On Monday, 25 June 2012 18:33:16 UTC+5:30, Gadget Steve wrote:

Install and use the Unicode version of wxPython.

-----Original Message-----

From: Prashant Deshmukh

Sent: 25 Jun 2012 12:48:51 GMT

To: wxpython-users@googlegroups.com

Subject: [wxPython-users] how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Hello everyone,

I am using

python 2.6

wxPython 2.8.12.1

to get string from wx.choice box i am using following code

mystringvalue = self.panels[i].chcchoice.GetStringSelection()

it works fine if wx.choice contains only alphanumerical characters.

it;s giving error when i am using special character like µ

and in this case giving error as

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xb5’

in position 9: ordinal not in range(128)

Can anyone help to resolve this.

Thanks

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Switching to the unicode build may not be the simplest solution, but it is the smartest. There will not be any more separate ansi builds of wxPython starting with 2.9.x, and it is likely that there will not be any more 2.8.x releases either. So switching to unicode now will make moving on to the next release much easier.

If you really must stick with the ansi build for some reason then you can solve this particular problem by telling wxPython to use a different encoding when it converts to/from string/unicode for the wx APIs, using something like wx.SetDefaultPyEncoding('utf-8')

BTW, how did the � get in to the wx.Choice string?

···

On 6/25/12 6:08 AM, Prashant Deshmukh wrote:

This is problem with just one of those strings. for this just installing
unicode version doesn't seem feasible.
does this don't have any simple solution.

--
Robin Dunn
Software Craftsman

This is problem with just one of those strings. for this just installing unicode version doesn’t seem feasible.
does this don’t have any simple solution.

Install and use the Unicode version of wxPython.

From: Prashant Deshmukh

Sent: 25 Jun 2012 12:48:51 GMT

To: wxpython-users@googlegroups.com

Subject: [wxPython-users] how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Hello everyone,

I am using

python 2.6

wxPython 2.8.12.1

to get string from wx.choice box i am using following code

mystringvalue = self.panels[i].chcchoice.GetStringSelection()

it works fine if wx.choice contains only alphanumerical characters.

it;s giving error when i am using special character like µ

and in this case giving error as

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xb5’

in position 9: ordinal not in range(128)

Can anyone help to resolve this.

Thanks

You problem is most probably on the Python level
side. Either wx28-ainsi (cp1252) or wx29-unicode
builds work fine. <>.GetStringSelecteion() return
correct values/type(class).

It should be noted. The character/glyph in question,
µ, unicode name ‘MICRO SIGN’, iso10*** French name,
SYMBOLE MICRON, is not even a particular Unicode
character as the code point value (0xb5) indicates.
It is a common element of in the occidental 8-bits
coding schemes and, consequently, it should probably
not be a problem with an occidental native wx-ansi
build.

k = [‘cp1252’, ‘iso-8859-1’, ‘cp437’, ‘cp850’,
‘cp858’, ‘iso-8859-1’, ‘mac-roman’]
for e in k:
print(u’µ’.encode(e))

b’\xb5’
b’\xb5’
b’\xe6’
b’\xe6’
b’\xe6’
b’\xb5’
b’\xb5’

but

u’µ’.encode(‘koi8-r’)
Traceback (most recent call last):
File “<pyshell#18>”, line 1, in
u’µ’.encode(‘koi8-r’)
File “C:\Python33\lib\encodings\koi8_r.py”, line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: ‘charmap’ codec can’t encode character ‘\xb5’ in position 0: character maps to

Toying with utf-8 usually leads to nothing. You may
have to use utf-8, only and only if you wish to display
this unicode µ char. This may be a potential issue related
to your question.

Final and general note. Special characters do not
exist, they are only characters.

jmf

···

On Monday, June 25, 2012 3:08:32 PM UTC+2, Prashant Deshmukh wrote:

On Monday, 25 June 2012 18:33:16 UTC+5:30, Gadget Steve wrote:

-----Original Message-----

Indeed, I did a mistake (typo).

The French name of the Unicode code point
U+00B5 (0xB5) is SYMBOLE MICRO (and not SYMBOLE MICRON).

(Just working/toying with this stuff)

Repaired.

jmf

···

On Wednesday, June 27, 2012 8:18:19 AM UTC+2, jmfauth wrote:

On Monday, June 25, 2012 3:08:32 PM UTC+2, Prashant Deshmukh wrote:

This is problem with just one of those strings. for this just installing unicode version doesn’t seem feasible.
does this don’t have any simple solution.

On Monday, 25 June 2012 18:33:16 UTC+5:30, Gadget Steve wrote:

Install and use the Unicode version of wxPython.

-----Original Message-----

From: Prashant Deshmukh

Sent: 25 Jun 2012 12:48:51 GMT

To: wxpython-users@googlegroups.com

Subject: [wxPython-users] how to get wx.choice.GetStringSelection() for strings which includes special character like µ

Hello everyone,

I am using

python 2.6

wxPython 2.8.12.1

to get string from wx.choice box i am using following code

mystringvalue = self.panels[i].chcchoice.GetStringSelection()

it works fine if wx.choice contains only alphanumerical characters.

it;s giving error when i am using special character like µ

and in this case giving error as

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xb5’

in position 9: ordinal not in range(128)

Can anyone help to resolve this.

Thanks

You problem is most probably on the Python level
side. Either wx28-ainsi (cp1252) or wx29-unicode
builds work fine. <>.GetStringSelecteion() return
correct values/type(class).

It should be noted. The character/glyph in question,
µ, unicode name ‘MICRO SIGN’, iso10*** French name,
SYMBOLE MICRON, is not even a particular Unicode
character as the code point value (0xb5) indicates.
It is a common element of in the occidental 8-bits
coding schemes and, consequently, it should probably
not be a problem with an occidental native wx-ansi
build.

k = [‘cp1252’, ‘iso-8859-1’, ‘cp437’, ‘cp850’,
‘cp858’, ‘iso-8859-1’, ‘mac-roman’]
for e in k:
print(u’µ’.encode(e))

b’\xb5’
b’\xb5’
b’\xe6’
b’\xe6’
b’\xe6’
b’\xb5’
b’\xb5’

but

u’µ’.encode(‘koi8-r’)
Traceback (most recent call last):
File “<pyshell#18>”, line 1, in
u’µ’.encode(‘koi8-r’)
File “C:\Python33\lib\encodings\koi8_r.py”, line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: ‘charmap’ codec can’t encode character ‘\xb5’ in position 0: character maps to

Toying with utf-8 usually leads to nothing. You may
have to use utf-8, only and only if you wish to display
this unicode µ char. This may be a potential issue related
to your question.

Final and general note. Special characters do not
exist, they are only characters.

jmf