Re: Yet another problem with special characters (Ä, Ö, Ü, etc.)

Dominik Reiter dominik.reiter at
Fri Oct 11 20:12:16 CEST 2002

> It could be a bug in your database module - I've never heard of
> "connective", where did it come from (unfortunately Googling for "python
> connective database module" didn't give helpful results).
> Normally one creates a database connection with the .connect() module,
> creates a cursor with connection.cursor(); if you are using the module
> correctly then it's perhaps not DB API compliant, but that hardly matters.
> What database back end are you using? Is the field defined as a Unicode
> field or as plain ASCII?
> Most likely you are simply having trouble interpreting your results. Note
> that whether you see the hex escape depends on whether Python uses repr()
> str() to produce what you are printing. Here's a little test program that
> shows you Python databases *can* work with these strange characters
> any text wrapping my mailer might do). I seem to remember HoldenWebSQL is
> Access database (blush) ...
> #
> # Database test
> #
> import mx.ODBC.Windows as db
> conn = db.connect("HoldenWebSQL")
> curs = conn.cursor()
> curs.execute("CREATE TABLE tst (txt VARCHAR(20) PRIMARY KEY)")
> curs.execute("INSERT INTO tst VALUES ('Österreich')")
> curs.execute("SELECT * FROM tst")
> result = curs.fetchall()
> print result
> country = result[0][0]
> print country, len(country), country[0]
> curs.execute("DROP TABLE tst")
> # End
> So, what happens when I run this? I get ...
> C:\Steve\Projects\Python>python
> [('\xd6sterreich',)]
> Österreich 10 Ö
> In  other words, when I print the list of tuples returned by the
> Python uses repr() to print the tuple components. When I extract the
> individual string, Python uses str() and all is well.
> Of course, now you have to decide whether you really are seeing a bug or
> not, and (if not) 'fess up! Hope this helps.

Hi Steve,

thanks for your quick answer. It helped me to figure out my problem. It's
how python handles the printing of tuples (using repr()). I had a tuple with
all the values for the database fields and this somehow didn't work. When I
tried to insert the necessary fields by string, I got a MySQL error, since
SQL expects not one large string but one string for each field. So I did
something like:

val = val + " ' " + inh + " ' " + ", "

and than stripped the string of the last ", " with val = val[:-2]

Now, everything works just fine and the value in the database reads
'Österreich'.    YESSSS !!!

Well, I think it was worth all those grey hairs I got ;-)

Again, thanks to everyone.

Until next time (which can't be to far in the future)

BTW, I wrote the module just to make sure I don't have all the
login-information in my script. It just makes me feel safer :-)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list