#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Charset problem!


    Hello,

    Im having a problem with python charset and german characters. I'm trying to obtain a string from the database using mysqldb trying this:

    array=result.fetch_row()[0]

    If i print the array i get all values and my string 'f\xfcr' <-- this is what i need

    but if i print array[stringlocation] i get 'f�r' that represent 66 fc 72 (why does this isn't unicode anymore?)

    If i write this to a file: 'fÌr' or hex 66 C3 BC 72

    I think that isn't a problem with mysqldb. i can't get the chars as i need.

    Note: I'm using set names latin1. if i use utf8 i will get doubles: f\xc3\xbcr

    Thank you for your help!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    Did you assign a datatype conversion dictionary in your connect function call?
    Your example comes out as typed in TeX
    f\"{u}r
    http://en.wikibooks.org/wiki/LaTeX/Accents
    just as you say.

    Running python3 and converting to utf8 I reproduce your result.
    Code:
    >>> A='f\xfcr'
    >>> bytes(A,'latin')
    b'f\xfcr'
    >>> bytes(A,'utf8')
    b'f\xc3\xbcr'
    >>> print(A)
    fr
    >>> 
    >>> with open('example.out', mode='w', encoding='latin') as output_stream:
    ...  output_stream.write(A)
    ...  output_stream.write('\n')
    ... 
    
    3
    1
    >>>
    This puts a line into example.out containing the German translation of "for".

    Hope this experiment helps resolve your trouble.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo