Hi,
Grzegorz Smith wrote:
Hi all. I have got situation: i load data from database(MSSQL) wchich are
encoded cp1250 and I fill template with that data (Cheetah Template), after
all i want to save template to file on disk. I'm using
newfile = open("template.html",w")
newfile.write(str(template))
newfile.close()
But data encodings are saved wrong, and I try diffrent programs to convert
but all i get was only mess. So is this any way to save data with encodings
cp1250 properly?
Any help will be very appreciated
Gregor
I had to do it recently, reading from mysql and pushing data into a
browser by cherryPy.
I used :
try:
val= dbString.decode('utf8').encode('iso-8859-1')
except UnicodeDecodeError:
val= dbString
The 'try:' was needed because of some extra-character on top of the 7
bits limit raising an exception.
I have no more explanations about that, and I must say it was a pain in
the neck to find a solution.
I guess in your case, you have to replace iso-8859-1 by something else
in the case it's not strictly the same that cp1250. The '4.9.2 Standard
Encodings' documentation section give some explanations.
Regards,
jm