How can I convert a string read from a database containing unicode literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
I have tried variations around
"Fr\u00f8ya".decode('latin-1')
but to no avail.
..david 5 1189
>>>><Da***********@sweco.no(DR) wrote:
>DRHow can I convert a string read from a database containing unicode literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"? DRI have tried variations around DR "Fr\u00f8ya".decode('latin-1') DRbut to no avail.
You have to use encode instead of decode, and the input string must be a
unicode string.
>>print u"Fr\u00f8ya".encode('latin-1')
Frøya
>>>
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
How can I convert a string read from a database containing unicode
literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
I have tried variations around
"Fr\u00f8ya".decode('latin-1')
but to no avail.
In [388]: 'Fr\u00f8ya'.decode('unicode-escape')
Out[388]: u'Fr\xf8ya'
In [389]: print 'Fr\u00f8ya'.decode('unicode-escape')
Frøya
Ciao,
Marc 'BlackJack' Rintsch
On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
>On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
>How can I convert a string read from a database containing unicode literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
I have tried variations around "Fr\u00f8ya".decode('latin-1') but to no avail.
In [388]: 'Fr\u00f8ya'.decode('unicode-escape') Out[388]: u'Fr\xf8ya'
In [389]: print 'Fr\u00f8ya'.decode('unicode-escape') Frøya
'unicode-escape' did the trick! Thank you!
..david
On 30 ene, 07:54, <David.Reks...@sweco.nowrote:
On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
How can I convert a string read from a database containing unicode
literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
In [388]: 'Fr\u00f8ya'.decode('unicode-escape')
Out[388]: u'Fr\xf8ya'
'unicode-escape' did the trick! Thank you!
A unicode-escaped string looks very strange in a database... I'd
revise the way things are stored and retrieved.
--
Gabriel Genellina
On 30. januar 2008 14:31, Gabriel Genellina wrote:
>On 30 ene, 07:54, <David.Reks...@sweco.nowrote:
>On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
>On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
>How can I convert a string read from a database containing unicode literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
>In [388]: 'Fr\u00f8ya'.decode('unicode-escape') Out[388]: u'Fr\xf8ya'
'unicode-escape' did the trick! Thank you!
A unicode-escaped string looks very strange in a database... I'd revise the way things are stored and retrieved.
I agree. I'm currently using the trick above to fix it.
..david This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gerhard Häring |
last post by:
>>> u"äöü"
u'\x84\x94\x81'
(Python 2.2.3/2.3b2; sys.getdefaultencoding() == "ascii")
Why does this work?
Does Python guess which encoding I mean? I thought Python should refuse
to guess...
|
by: Laurent Therond |
last post by:
Maybe you have a minute to clarify the following matter...
Consider:
---
from cStringIO import StringIO
def bencode_rec(x, b):
t = type(x)
|
by: Guilherme Salgado |
last post by:
Hi there,
I have a python source file encoded in unicode(utf-8) with some
iso8859-1 strings. I've encoded this file as utf-8 in the hope that
python will understand these strings as unicode...
|
by: nico |
last post by:
In my python scripts, I use a lot of accented characters as I work in
french.
In order to do this, I put the line
# -*- coding: UTF-8 -*-
at the beginning of the script file.
Then, when I need...
|
by: wolfgang haefelinger |
last post by:
Hi,
I wonder whether someone could explain me a bit what's going on here:
import sys
# I'm running Mandrake 1o and Windows XP.
print sys.version
## 2.3.3 (#2, Feb 17 2004, 11:45:40)
|
by: Onega |
last post by:
Hi
I create a simple win32 project (VC2003, windows2003(English) ,
and do simple paint in WM_PAINT message, when the project use
multi-character set, it is OK.
but when I change to UNICODE,...
|
by: John Salerno |
last post by:
Forgive my newbieness, but I don't quite understand why Unicode is still
something that needs special treatment in Python (and perhaps
elsewhere). I'm reading Dive Into Python right now, and it...
|
by: abhi147 |
last post by:
Hi ,
I want to convert an array of bytes like :
{79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3}
into Unicode character with ISO-8859-1 standard.
Can anyone help me .. how should...
|
by: Paul Johnston |
last post by:
Hi
I have a string which I convert into a list then read through it
printing its glyph and numeric representation
#-*- coding: utf-8 -*-
thestring = "abcd"
thelist = list(thestring)
for c...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |