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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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. ... |
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,
...
|
|
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 ... |
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. ... |
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 ... |
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 ...
|
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 ... |
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', ...
|
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 ... |
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 ... |
for example the following:
str(u'????')
will throw an error.
how can i prevent these?
|
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 ... |
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 ... |
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 ... |
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 ...
|
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 ...
|
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 ...
|
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 ... |
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 ... |
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 ...
|
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 ...
|
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,
...
|
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 ... |
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 ... |
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 ...
|
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 ...
|
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 ...
|
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 ????
|
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"", ... |
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 ... |
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. ... |
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 ... |
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 ... |
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, ... |
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 ... |
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.
|
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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
|
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 ... |
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 ... |
|
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 ... |
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, ... |
|
def fetchinfo(asset_id): #This function will fetch info about the machine conn = sqlite3.connect("bookeeper.db") c = conn.cursor() print"""Testfetch1""" ... |