Is there any reason to prefer unicode(somestring, 'utf8') as opposed to somestring.decode('utf8')?
My only thought is that .decode() is a bound method so python may be able to resolve it more efficiently, ... |
This is in python 2.4. Here is my situation. I pull a string from a database, and it contains an umlauted 'o' (\xf6). At this point if I run type(value) it ... |
I have terminal.app set to accept utf-8 and in bash I can type unicode characters, copy and paste them, but if I start the python shell I can't and if I ... |
I've got a problem with strings that I get from one of my clients over xmlrpc. He sends me utf8 strings that are encoded twice :( so when I get them ... |
I'm using python's base64 module and I get a string that can be encoded or not encoded. I would like to do something like:
if isEncoded(s):
output = base64.decodestring(s)
else:
...
|
I'm writing a parser, and there is LOTS of text to decode but most of my users will only care about a few fields from all the data. So I only ... |
Inside my python scrip, I get some string back from a function which I didn't write. The encoding of it varies. I need to convert it to ascii format. Is there ... |
|
What would the best way of unpacking a python string into fields
I have data received from a tcp socket, it is packed as follows, I believe it will be in a ... |
s = 'Tara%2520Stiles%2520Living'
How do I turn it into:
Tara Stiles Living
|
I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are ... |
Trying to decode an invalid encoded utf-8 html page gives different results in
python, firefox and chrome.
The invalid encoded fragment from test page looks like 'PREFIX\xe3\xabSUFFIX'
>>> fragment = 'PREFIX\xe3\xabSUFFIX'
>>> fragment.decode('utf-8', 'strict')
...
UnicodeDecodeError: 'utf8' ...
|
it works fine on 64 bit machines but for some reason will not work on python 2.4.3 on a 32-bit instance.
i get the error
'utf8' codec can't decode bytes in position ...
|
I have an old C# program that is being ported to Python 3 for different reasons. Basically, what the program does is to fetch a website and search its content (and ... |
In a text file (test.txt), my string looks like this:
Gro\u00DFbritannien
Reading it, python escapes the backslash:
>>> file = open('test.txt', 'r')
>>> input = file.readline()
>>> input
'Gro\\u00DFbritannien'
How can I have this interpreted as unicode? decode() ... |
When profiling our code I was surprised to find millions of calls to
C:\Python26\lib\encodings\utf_8.py:15(decode)
I started debugging and found that across our code base there are many small bugs, ... |
Platform: App Engine
Framework: webapp / CGI / WSGI
On my client side (JS), I construct a URL by concatenating a URL with an unicode string:
http://www.foo.com/??
then I call encodeURI to get
http://www.foo.com/%E5%9C%B0%E9%9C%87
and I put ... |
In Python 2, converting the hexadecimal form of a string into the corresponding unicode was straightforward:
comments.decode("hex")
where the variable 'comments' is a part of a line in a file (the rest of ... |
Can someone give an advice of how to decode these strings?
They are parts of email subjects.
=?Windows-1251?B?ICLRLcvu5Obo8fLo6iI?=
=?koi8-r?B?5tLPzM/XwSDtwdLJzsEg98nUwczYxdfOwQ?=
=?Windows-1251?B?1PDu6+7i4CDM4PDo7eAgwujy4Ov85eLt4A?=
It's probably necessary to take inner part of string ICLRLcvu5Obo8fLo6iI and then base64.decodestring(string).decode('windows-1251')
Such an approach ... |
I'm using BeautifulSoup, and I get back a string like this:
u'Dassault Myst\xe8re'
It's a unicode, but what I want is to make it look like:
'Dassault Mystère'
I have tried
name = name.encode('utf-8'), decode(), ...
|
=?UTF-8?B?TmV3IFBlcnNvbmFsIE1lc3NhZ2U6IE1vbmcgYW5oIHTDrG0gbOG6oWkgY2h1eWVudGIub3JnIQ==?=
Hi, I have this string which is what returned from an IMAP command - do anyone know how to decode this in python so I'll have the proper UTF-8 string?
|
This is the code:
>>> import base64
>>> id = 1
>>> key = "secret key very long"
>>> enc = base64.urlsafe_b64encode(str(id)+key)
>>> enc
'MXNlY3JldCBrZXkgdmVyeSBsb25n'
>>> base64.urlsafe_b64decode(enc)
'1secret key very long'
Works as intended on my machine, but when I ... |
I have some strings with all this kind of characters in it which also has normal letters ,
and i want to transform all the "wired" characters in they're normal representation .
So ... |
I've got what's supposed to be a UCS-2 encoded xml document that I've managed to build a DOM based on minidom after some tweaking.
The issue is that I'm supposed to have ... |
I am reading a first and last name in Python from a file and am having trouble with encoding. I want to print out the name, but am getting "UnicodeEncodeError: 'charmap' ... |
I have a string from reading a .txt file that looks something like this:
str='\x00I\x00S\x00T\x00A\x00\r\x00\n\x00[\x00/\x00B\x00O\x00D\x00Y\x00]\x00\r\x00\n\x00'
The contents of the file is in Portuguese and it won't allow me to encode into utf-8.
When I ... |
I'm having some trouble with Python's raw_input command (Python2.6),
For some reason, the raw_input does not get the converted string that swedify() produces and this giving me a encoding error which i'm ... |
i have file having name "SSE-Künden, SSE-Händler.pdf" which having those two unicode char ( ü,ä) when i am printing this file name on python interpreter the unicode values are getting ... |
Writing my code for Python 2.6, but with Python 3 in mind, I thought it was a good idea to put
from __future__ import unicode_literals
at the top of some modules. In other ... |
I get the following string from database:
'23:45 \xe2\x80\x93 23:59'
and the output should look like
'23:45 - 23:59'
How can I decode this? I tried utf-8 ... |
string.decode('hex') by ScoutDavid Sun Apr 03, 2011 11:50 am I have this string: Code: Select all myString = "DE2A2A" And then I try to decode it, by doing myString.decode('hex'). If you try it in IDLE you'll get it fine, but in the middle of my program, I get this: Code: Select all Traceback (most recent call last): File ... |
|