Questions tagged [python-unicode]

Python distinguishes between byte strings and unicode strings. *Decoding* transforms bytestrings to unicode; *encoding* transform unicode strings to bytes.

Python distinguishes between byte strings and unicode strings. Decoding transforms bytestrings to unicode; encoding transform unicode strings to bytes.

Remember: you decode your input to unicode, work with unicode, then encode unicode objects for output as bytes.

See the

1053 questions
0
votes
1 answer

Reliable `print(repr(context))` for Python 3

I am debugging a complex issue and need to see the content of structured variable named context. Attempt to print it with this code fails: print(repr(context)) With error message: UnicodeEncodeError: 'charmap' codec can't encode character '\xb6' in…
anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
0
votes
1 answer

Why Do I get an empty output in scrapy for my items?

I'm a newbie in python and scrapy. I'm going to scrape a page of some links to get my desired data but when i generate my output, my desired items are empty. My items.py code is as follows: class CinemaItem(Item): url = Field() name =…
sepidfekr
  • 11
  • 1
  • 4
0
votes
1 answer

Python HTML dump unicode error

I am creating a system where all urls, html, text, links, etc are stored in unicode format. For that purpose, I extract html from a web page and convert it to unicode using the code pasted here. A few links I tried work fine. Others like the link…
Pratik Poddar
  • 1,353
  • 3
  • 18
  • 36
0
votes
2 answers

Python encoding error when trying to print a QString

I try to print a PyQt4.QtCore.QString object: print str(type(html)) print str(html) However, I get the following error: Traceback (most recent call last): File "download.py", line 23, in print…
toom
  • 12,864
  • 27
  • 89
  • 128
0
votes
1 answer

Unicode renders differently in python due to overlooking incorrect logic flow of two seemingly identical procedures

I've tried to write a test() function to help parsing strings to Tibetan unicode, so I can see if my invariants are still kept when adding new features. Here's everything in its entirety: import sys from math import * ''' Translator Wylie to…
jollyroger
  • 659
  • 1
  • 10
  • 19
0
votes
1 answer

Unable to decode byte

So, I am obtaining some xml data. One such example, is as follows: xmlString = 'san diego, ça' This is currently as a string. I now need to convert it to a XML object, by using ElementTree, fromstring() method. The import is as…
redrubia
  • 2,256
  • 6
  • 33
  • 47
0
votes
0 answers

SQL Server raw query returns empty in Django when query is unicode

I have an Ubuntu 13.10 server, Django 1.5 application and Sql Server 2008 and I try to execute a raw query which works fine if it is only without unicode. Sample Model: class SomeRecords(models.Model): EntryName =…
cem
  • 1,535
  • 19
  • 25
0
votes
2 answers

Erasing all unreadable characters in tab-delimited txt

I am running a python program to process a tab-delimited txt data. But it causes trouble because it often has unicodes such as U+001A or those in http://en.wikipedia.org/wiki/Newline#Unicode (Worse, these characters are not even seen unless the txt…
0
votes
3 answers

Comparing unicode with unicode in python

I am trying to count the number of same words in an Urdu document which is saved in UTF-8. so for example I have document containing 3 exactly same words separated by space خُداوند خُداوند خُداوند I tried to count the words by reading the file…
mdanishs
  • 1,996
  • 8
  • 24
  • 50
0
votes
1 answer

Python unicode issue with subprocess.call

My parser function uses lxml and provides me a list of unicode strings (book_list). The strings are joined together into a file name, cleaned up and then passed via subprocess.call to another binary which continues the work. My problem is that the…
Joseph jun. Melettukunnel
  • 6,267
  • 20
  • 69
  • 90
0
votes
1 answer

Python : Convert ascii string to unicode string

I have an ascii string, e.g. "\u005c\u005c192.150.4.89\u005ctpa_test_python\u005c5.1\u005c\videoquality\u005crel_5.1.1Mx86\u005cblacklevelsetting\u005c\u5e8f\u5217\u5e8f\u5217.xml" And I want to convert it into unicode and dump into a file, so that…
0
votes
2 answers

Unicode - Just print the string

print proc1 "\u001b[H\u001b[2J\r\nPRINT ME" How to print only "PRINT ME". I do not want to print other chunks. The above is an output of a shell script when Python fabric gives a run call. I return the fabric message to my Flask as return…
Sathy
  • 303
  • 2
  • 8
  • 18
0
votes
3 answers

Converting Unicode Values as String from a Python Dictionary

I've built a python dictionary as follows: result = {} for fc in arcpy.ListFeatureClasses(): for field in arcpy.ListFields(fc): result.setdefault(field.name, []).append(fc) which takes the name of the fields in each table (feature…
Mike
  • 4,099
  • 17
  • 61
  • 83
0
votes
0 answers

How can I install python or python packages with a specific PyUnicode?

I am trying to install PyFFTW a pythonic wrapper for FFTW. When I do so I get the following error. ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so : undefined symbol : PyUnicodeUCS2_FromUnicode Vaarious websites…
E. Lee
  • 41
  • 1
  • 7
0
votes
1 answer

Accessing the original value of the unicode string when subclassing unicode

Try to get a class which would work like so: >>> original = u"ABCD-123-foo" >>> suffix = SuffixComparingUnicodeString("foo") >>> suffix == original # if original ends with suffix, True True I know it's silly. Please bear with me. Anyway, I can't…
2rs2ts
  • 10,662
  • 10
  • 51
  • 95