Not able to get utf8 encoded string into a document
Tim Golden
mail at timgolden.me.uk
Fri May 9 16:55:48 EDT 2008
Lawrence, Anna K (US SSA) wrote:
> I am working on a web application using Pylons .0.9.6, SQLAlchemy 0.4.4,
> MySQLdb 1.2.2 and Python 2.4.4.
>
> We want to use utf8 encoding throughout and as far as I can see
> everything is set properly between components and I’ve got a
> sitecustomize.py in my site-packages directory of python set to utf8 as
> well. Everything is stored properly in the database and displays nicely
> in the app. However, when I try to take a string that is coming out of
> the database and export it to a Word document, no amount of
> encoding/decoding will make the Word doc display properly.
>
> Since I’m on a Windows machine, my default locale is cp437. Is this the
> reason?
From where I'm sitting, I can't see enough to help. The crucial
thing seems to be in this phrase: "When I try to take a string that
is coming out of the database and export it to a Word document,
no amount of encoding/decoding will make the Word doc display properly".
It presumably doesn't matter what web framework etc. you're using:
you either get a unicode object or an encoded string from the database
and you're putting that in a Word doc. Is that correct?
Can you provide a sample of code which shows what you're doing, and
explain what does / doesn't happen? By way of trying to get closer,
there's a Noddy example below:
<code>
import win32com.client
word = win32com.client.gencache.EnsureDispatch ("Word.Application")
word.Visible = 1
doc = word.Documents.Add ()
doc.Range ().Text = u"poup\u00e9e"
</code>
Now, on my Win2K machine this displays perfectly well in word with
the French word poupee with the penultimate e having an acute
accent. So, translating this minimalist example into your situation,
what happens when you try doing this?
TJG
More information about the Python-list
mailing list