decode « string « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » string » decode 

1. unicode() vs. str.decode() for a utf8 encoded byte string (python 2.x)    stackoverflow.com

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, ...

2. Unable to decode unicode string in Python 2.4    stackoverflow.com

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 ...

3. Can't decode utf-8 string in python on os x terminal.app    stackoverflow.com

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 ...

4. Decoding double encoded utf8 in Python    stackoverflow.com

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 ...

5. Given a string, how do I know if it needs decoding    stackoverflow.com

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:
  ...

6. Python: Lazy String Decoding    stackoverflow.com

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 ...

7. What is the fool proof way to convert some string (utf-8 or else) to a simple ASCII string in python    stackoverflow.com

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 ...

8. Decoding packed data into a structure    stackoverflow.com

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 ...

9. If I have this string in Python, how do I decode it?    stackoverflow.com

s = 'Tara%2520Stiles%2520Living' How do I turn it into:

Tara Stiles Living

10. Python string decoding issue    stackoverflow.com

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 ...

11. Why is python decode replacing more than the invalid bytes from an encoded string?    stackoverflow.com

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' ...

12. Python UTF-8 can't decode byte on 32-bit machine    stackoverflow.com

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 ...

13. What is the better error handling method for decoding Python bytes to unicode strings?    stackoverflow.com

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 ...

14. Python file input string: how to handle escaped unicode characters?    stackoverflow.com

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() ...

15. Can I turn off implicit Python unicode conversions to find my mixed-strings bugs?    stackoverflow.com

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, ...

16. Having encoded a unicode string in javascript, how can I decode it in Python?    stackoverflow.com

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 ...

17. Decode Hex String in Python 3    stackoverflow.com

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 ...

18. python : decode strings    stackoverflow.com

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 ...

19. Unicode issue, correctly decoding/encoding string in python    stackoverflow.com

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(), ...

20. Decode this type of string in python    stackoverflow.com

=?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?

21. appengine base64 encoded string is different from my local machine's    stackoverflow.com

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 ...

22. Decoding a string in python ... with _\x08__\x08_d\x08de\x08el\x08li\x08it\x08te\x08em in it     stackoverflow.com

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 ...

23. python base64 string decoding    stackoverflow.com

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 ...

24. python encoding and decoding strings    stackoverflow.com

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' ...

25. Cannot properly decode string    stackoverflow.com

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 ...

26. Python - Encoding string - Swedish Letters    stackoverflow.com

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 ...

27. Handling ascii char in python string    stackoverflow.com

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 ...

28. (unicode error) 'unicodeescape' codec can't decode bytes - string with '\u'    stackoverflow.com

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 ...

29. python decoding string issues    stackoverflow.com

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 ...

30. string.decode('hex')    python-forum.org

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 ...

31. Decode UTF-8 Strings    python-forum.org

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.