unicode « 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 » unicode 

1. Will everything in the standard library treat strings as unicode in Python 3.0?    stackoverflow.com

I'm a little confused about how the standard library will behave now that Python (from 3.0) is unicode-based. Will modules such as CGI and urllib use unicode strings or will they ...

2. conversion of unicode string in python    stackoverflow.com

I need to convert unicode strings in Python to other types such as unsigned and signed int 8 bits,unsigned and signed int 16 bits,unsigned and signed int 32 bits,unsigned and signed ...

3. Python c-api and unicode strings    stackoverflow.com

I need to convert between python objects and c strings of various encodings. Going from a c string to a unicode object was fairly simple using PyUnicode_Decode, however Im not sure ...

4. Converting to Precomposed Unicode String using Python-AppKit-ObjectiveC    stackoverflow.com

This document by Apple Technical Q&A QA1235 describes a way to convert unicode strings from a composed to a decomposed version. Since I have a problem with file ...

5. Should I use Unicode string by default?    stackoverflow.com

Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types ...

6. Python __str__ versus __unicode__    stackoverflow.com

Is there a python convention for when you should implement __str__() versus __unicode__(). I've seen classes override __unicode__() more frequently than __str__() but it doesn't appear to be consistent. ...

7. How do I get str.translate to work with Unicode strings?    stackoverflow.com

I have the following code:

import string
def translate_non_alphanumerics(to_translate, translate_to='_'):
    not_letters_or_digits = u'!"#%\'()*+,-./:;<=>?@[\]^_`{|}~'
    translate_table = string.maketrans(not_letters_or_digits,
            ...

8. Writing unicode strings via sys.stdout in Python    stackoverflow.com

Assume for a moment that one cannot use print (and thus enjoy the benefit of automatic encoding detection). So that leaves us with sys.stdout. However, sys.stdout is so dumb as to ...

9. What does 'u' mean in a list?    stackoverflow.com

This is the first time I've came across this. Just printed a list and each element seems to have a u in front of it i.e. ...

10. How do I include unicode strings in Python doctests?    stackoverflow.com

I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that ...

11. Python unicode: how to test against unicode string    stackoverflow.com

I have a script like this:

#!/Python26/
# -*- coding: utf-8 -*-

import sys
import xlrd
import xlwt

argset = set(sys.argv[1:])

#----------- import ----------------
wb = xlrd.open_workbook("excelfile.xls")

#----------- script ----------------
#Get the first sheet either by name
sh = wb.sheet_by_name(u'Data')

hlo = []

for ...

12. Can't use unichr in Python 3.1    stackoverflow.com

new here! I'm a beginner in Python, and I've been looking through the Python Cookbook (2nd Edition) to learn how to process strings and characters. I wanted to try converting a ...

13. Python unicode question    stackoverflow.com

I have a list that I need to send through a URL to a third party vendor. I don't know what language they are using. The list prints out like this:

[u'1', ...

14. Python Unicode strings and the Python interactive interpreter    stackoverflow.com

I'm trying to understand how python 2.5 deals with unicode strings. Although by now I think I have a good grasp of how I'm supposed to handle them in code, I ...

15. Return unicode string from python via ajax    stackoverflow.com

I have a small webapp that runs Python on the server side and javascript (jQuery) on the client side. Now upon a certain request my Python script returns a unicode string and ...

16. why in python giving to str func a unicode string will throw an exception?    stackoverflow.com

for example the following: str(u'????') will throw an error. how can i prevent these?

17. Why does Python output a string and a unicode of the same value differently?    stackoverflow.com

I'm using Python 2.6.5 and when I run the following in the Python shell, I get:

>>> print u'Andr\xc3\xa9'
André
>>> print 'Andr\xc3\xa9'
André
>>>
What's the explanation for the above? Given u'Andr\xc3\xa9', how can I ...

18. How do I convert a unicode to a string at the Python level?    stackoverflow.com

The following unicode and string can exist on their own if defined explicitly:

>>> value_str='Andr\xc3\xa9'
>>> value_uni=u'Andr\xc3\xa9'
If I only have u'Andr\xc3\xa9' assigned to a variable like above, how do I convert it to ...

19. Conversion of strings like \\uXXXX in python    stackoverflow.com

I have a string like \uXXXX (representation) and I need to convert it into unicode. I receive it from 3rd party service so python interpreter doesn't convert it and I need conversion ...

20. Why does Python sometimes upgrade a string to unicode and sometimes not?    stackoverflow.com

I'm confused. Consider this code working the way I expect:

>>> foo = u'Émilie and Juañ are turncoats.'
>>> bar = "foo is %s" % foo
>>> bar
u'foo is \xc3\x89milie and Jua\xc3\xb1 are ...

21. Python's string.translate() doesn't fully work?    stackoverflow.com

Given this example, I get the error that follows:

print u'\2033'.translate({2033:u'd'})

C:\Python26\lib\encodings\cp437.pyc in encode(self, input, errors)
     10
     11     def encode(self,input,errors='strict'):
---> 12 ...

22. How to use unicode inside an xpath string? (UnicodeEncodeError)    stackoverflow.com

I'm using xpath in Selenium RC via the Python api. I need to click an a element who's text is "Submit »" Here's the error that I'm getting:

In [18]: sel.click(u"xpath=//a[text()='Submit \xbb')]")
---------------------------------------------------------------------------
UnicodeDecodeError   ...

23. does google app engine display unicode differently in StringProperty v StringListProperty objs?    stackoverflow.com

I have a db.StringProperty() mRegion that is set to some Korean text. I see in my Dashboard that the value is visibly in Korean like this: ?? : ???? However, when I ...

24. strings in hebrew in python for s60    stackoverflow.com

I'm using python for S60. I want to use string in hebrew, to represent them on the GUI and to send them in SMS message. It seems that the PythonScriptShell don't accept such ...

25. Testing Python console programs with Unicode strings in NetBeans 6.9    stackoverflow.com

I try to run the following simple code in NetBeans 6.9

s = u"\u00B0 Celsius"
print u"{0}".format(s)
But I get the following error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not ...

26. How to generate hebrew strings in python 3?    stackoverflow.com

I'm trying to create hebrew strings but get syntax errors. It works in the IDLE shell but not in Pydev. Here's what I've tried so far:

s = '?????? ??????' #works in the ...

27. Strings in Python 3    stackoverflow.com

I am programing VIX API from python 2.5, but now I want to port the code to python 3.2 This funtion opens the virtual machine:

self.jobHandle = self.VixLib.vix.VixVM_Open(self.hostHandle,
    ...

28. Python 2.x: how to automate enforcing unicode instead of string?    stackoverflow.com

How can I automate a test to enforce that a body of Python 2.x code contains no string instances (only unicode instances)? Eg. Can I do it from within the code? Is there a ...

29. Python - can I detect unicode string language code?    stackoverflow.com

I'm faced with a situation where I'm reading a string of text and I need to detect the language code (en, de, fr, sp, etc). Is there a simple way to ...

30. Problem with unescaping unicode strings    stackoverflow.com

I have a problem with unescapting unicode string. I tried the following, but it doesn't work with unicode chars.

>>> s = ur"\'test\'"
>>> s.decode("string_escape")
"'test'"
>>> s = ur"\'test \u2014\'"
>>> s.decode("string_escape")
Traceback (most recent call ...

31. String In python with my unicode?    stackoverflow.com

Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> str_version = '??????'
>>> type(str_version)
<class 'str'>
>>> print (str_version)
??????
>>> unicode_version = '??????'.decode('utf-8')
Traceback ...

32. How to write unicode strings into a file?    stackoverflow.com

I am using python 2.6.5 I want to write some japanese characters to a file. I am getting this error & I don't know how to change the encoding.

Python 2.6.5 (r265:79063, Jun 12 ...

33. Unicode strings in tornado web app    stackoverflow.com

How can I use unicode strings in tornado views or templates?
I insert in template
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> And in view

# -- coding: utf-8 --
Output is ????

34. Best way to do a "not None" test in Python for a normal and Unicode empty string?    stackoverflow.com

In Python 2.7, I'm writing a class that calls a function in an API which might, or might not, return an empty string. Furthermore, the empty string might be unicode u"", ...

35. Python, len and slices on unicode strings    stackoverflow.com

I am handling a situation where I need to make a string fit in the allocated gap in the screen, as I'm using unicode len() and slices[] work apparently on bytes ...

36. How to view crawled unicoded arabic string?    stackoverflow.com

I have crawled some webpages using Python. I ripped off the html tags and only stored some content of those pages as repr(s). Most of those pages are not in English. ...

37. how to get rid of unicode u'string' prefix in Python    stackoverflow.com

I assume this is an easy question, I even haven't found an answer on the Web. I have a string that is unicode encoded and when I print it to the console ...

38. Convert string to unicode    stackoverflow.com

import hashlib
string1 = u'test'
hashstring = hashlib.md5()
hashstring.update(string1)
string2 = hashstring.digest()

unicode(string2)

UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position 1: ordinal
not in range(128)
The string HAS to be unicode for it to be any use ...

39. Python string conversion (localization) question    stackoverflow.com

source = '\xe3\xc7\x9f'
destination = u'\u0645\u0627\u06ba'
How do I get from the source, to the destination? (The source and the destination are both the same 3 characters, in the same order, just represented differently.) Technically, ...

40. handling unicode strings in Windows    stackoverflow.com

For the frist time, I was trying out one of my pythin scripts, which deals with unicode charecters, on Windows (Vista) and found that it's not working. The script works perfectly ...

41. How to make unicode string with python3    stackoverflow.com

I used this :

u = unicode(text, 'utf-8')
But getting error with Python 3 (or... maybe I just forgot to include something) :
NameError: global name 'unicode' is not defined
Thank you.

42. Trying to combine this list of unicode strings    stackoverflow.com

Trying to combine this list of unicode strings. I've tried both using sum as well as using join. No luck. Any idea how I can do this? I just want a plain ...

43. Does whoosh require all strings to be unicode?    stackoverflow.com

I am redoing my search app in Whoosh from Solr. I am now learning from the quick start. But I kept running into problems each time I had to deal with ...

44. Able to run Python code with Unicode string in Eclipse, but getting UnicodeEncodeError when running via command line or Idle.    stackoverflow.com

I've experienced this a lot, where I'll decode/encode some string of Unicode in Eclipse (PyDev), and it runs fine and how I expected, but then when I launch the same script ...

45. write()-ing an encoded string in Python 3.x    stackoverflow.com

I've got a unicode string (s) which I want to write into a file. In Python 2 I could write:

open('filename', 'w').write(s.encode('utf-8'))
But this fails for Python 3. Apparently, s.encode() returns something of type ...

46. Python efficient obfuscation of string    stackoverflow.com

I need to obfuscate lines of Unicode text to slow down those who may want to extract them. Ideally this would be done with a built in Python module or a ...

47. python : change unicode string into list?    stackoverflow.com

I get the data as type <type 'unicode'>

u'{0.128,0.128,0.133,0.137,0.141,0.146,0.15,0.155,0.159,0.164,0.169,0.174,0.179,0.185,0.19,0.196,0.202,0.208,0.214,0.22}'  
I want to convert this to list like
[0.128,0.128,0.133,0.137,0.141,0.146,0.15,0.155,0.159,0.164,0.169,0.174,0.179,0.185,0.19,0.196,0.202,0.208,0.214,0.22]
How can I do this with python? Thank you

48. Unicode string Python    stackoverflow.com

I need to write to a file a string that contains the degree sign (°). This string is stored in variable and, as expected, when I try: f.write(myVariable.encode('utf-8')) I get UnicodeDecodeError. If I ...

49. Is there any good reason not to use unicode as opposed to string?    stackoverflow.com

Many problems I've ran into in Python have been related to not having something in Unicode. Is there any good reason to not use Unicode by default? I understand needing to ...

51. unicode filenames/strings in os.system    python-forum.org

I have a folder with unicode filenamed files in it. I use os.listdir() to get list of all the files in the folder and also print the file names using file.encode('UTF-8'). Works good so far. But when i pass this file name into os.system() command it errors out saying the file doesnt exist. See code below. What do i have to ...

52. regular strings from unicode in lists    python-forum.org

Thanks for the quick reply! I tried it, and it definitely changed my output, but I ended up changing str to float...I know there's some sort of floating point error that happens,but I'll tackle one issue at a time. anyway, the reason I'm changing it to a float is, when it was just a string, I'd try to sort my data, ...

53. UNICODE Strings    python-forum.org

54. How do u convert unicode strings 2 standard strings?    python-forum.org

def fetchinfo(asset_id): #This function will fetch info about the machine conn = sqlite3.connect("bookeeper.db") c = conn.cursor() print"""Testfetch1""" ...

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.