On 1/13/21 7:59 PM, Grant Edwards wrote:
On 2021-01-13, n952162 <[email protected]> wrote:

Hello. In python3, how do you do this?
Please explain what "this" is trying to accomplish, and we can tell
you how to do it in Python3. Are you trying to convert from Unicode to
Latin1 and back to Unicode?

   Python 3.8.6 (default, Jan  2 2021, 20:25:58)
   [GCC 9.3.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> 'gebuchte Umsätze;'.encode('latin1').decode('latin1')
   'gebuchte Umsätze;'


I'm trying to search for a string in a file.  I don't know why there
needs to be any conversion going on.

Just running python3 in interactive mode, I can input the literal when
the locale is right:

   12/lcl/data/f/b>LC_ALL=de_DE python3
   Python 3.7.9 (default, Nov 16 2020, 00:32:07)
   [GCC 9.3.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   Could not open PYTHONSTARTUP
   FileNotFoundError: [Errno 2] No such file or directory:
   '/home/mellman/lib/python/rpnrc'
    >>> s = "gebuchte Umsätze"
    >>> print (s)
   gebuchte Umsätze
    >>>

but it doesn't work from within my pgm...

With python2, I presume there was conversion going on because ... a
string can't have unicode chars, so it must be a unicode string that has
to be decoded.

   tgt = unicode ('gebuchte Umsätze;'.decode ('latin1'))

But python3 is supposed to make all that superfluous ... I thought that
was a major driving factor for python3 ... that everything was unicode,
conversion wouldn't be necessary.


Reply via email to