string encoding - how to make it work

Henry Baumgartl h.baumgartl at chello.NOSPAM.nl
Wed Jul 17 07:03:04 EDT 2002


Hello all,

Looking through material i could find on the matter, i haven't been able to
find a workable solution that will allow me to write code that will take
keyboard string input from any Python supported OS, and generate identical
strings anywhere else.

For example:

On my W2K box, command line input has no problems dealing with defined
short-cuts, as in:
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> aes='dëf'

In IDLE this generates the Error:
UnicodeError: ASCII encoding error: ordinal not in range(128)

(the standard Python command line interpreter accepts this definition and
subsequent print statements without a problem)

The following works on IDLE, although print generates an unprintable
character:
>>> aes='d\x89f'
>>> aes
'd\x89f'
>>> print aes
d‰f

The next issue is that even when the input is accepted, reading the string
from different applications becomes an unpredictable adventure.

Is there a way, using standard string methods, to write code that will
always generate the same output?

Best regards,
Henry





More information about the Python-list mailing list