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

960 questions
-2
votes
1 answer

Example with different sort order between raw char and unicode?

I'd like to test some program on whether it can recognize Unicode chars and sort them correctly. Can anybody provide some examples Unicode chars whose raw char representation will be sorted differently from the Unicode representation? Thanks.
user1424739
  • 7,204
  • 10
  • 38
  • 67
-2
votes
1 answer

importing csv files in python unicode error unicodeescape

I am trying to work on a csv file in python #code experiments import csv from statistics import mean with open("C:\Users\xyr\zzz\kkkk\mmmm\ooooo\mpg.csv",'r') as csvfile: reader=list(csv.DictReader(csvfile)) for item in reader: …
ss321c
  • 551
  • 1
  • 6
  • 18
-2
votes
1 answer

Converting unicode to devanagari in Python

I need to map each Unicode value in final2 with the Unicode values present as keys in the dictionary to print the Devanagari characters in a string. Right now the output generated is an empty list. How do I print the Devanagari characters in a…
Sheryl
  • 51
  • 6
-2
votes
2 answers

Transform unicode \xe9 to é (python 2.7)

I'm trying to transform this unicode value: string_value = u'd\xe9cid\xe9' to string_value = u'décidé' I feel like I've tried everything: decoded_str = string_value.decode('utf-8') or string_value = str(string_value) decoded_str =…
PAscalinox
  • 37
  • 1
  • 10
-2
votes
2 answers

Python 3 UnicodeEncodeError (Apache)

With this code: #!/usr/bin/env python3 open("We’re-introducing-a-DNS-man.jpg", "wb") I get the error: UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 2: ordinal not in range(128) The error only occurs when running the…
Sam Bull
  • 1,718
  • 1
  • 12
  • 16
-2
votes
1 answer

Python unicode conversion

I have the following unicode: s = u'\\u5b50'. I want to convert s to m = u'\u5b50'. How do I do it? s = u'\\u5b50' m = u'\u5b50' print len(s) # 6 print len(m) # 1 print s # \u5b50 print m # 子
Transcendental
  • 889
  • 2
  • 8
  • 25
-2
votes
1 answer

exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\xc3' in position 12: ordinal not in range(128)

I'm using web2py framework and i'm getting the error 'ascii' codec can't encode character u'\xc3' in position 12: ordinal not in range(128) only if i try to use the string value of…
Diogo Martins
  • 887
  • 7
  • 15
-2
votes
1 answer

read a unicode text file using python

when I read the file it's coming out with all very odd characters special characters I don't understand. How do I get python to read the file in the same way notepad++ does? the text file came from exporting an email from lotus notes 9 to unicode…
yoshiserry
  • 14,991
  • 24
  • 67
  • 96
-2
votes
1 answer

string matching from unicode text file? python

import re, codecs import string import sys stopwords=codecs.open('stopwords_harkat1.txt','r','utf_8') lines=codecs.open('Corpus_v2.txt','r','utf_8') for line in lines: line = line.rstrip().lstrip() #print line tokens = line.split('\t') …
msm
  • 21
  • 1
  • 5
-3
votes
1 answer

make unicode a string stored in a variable and then send it with telepot

Introduction I'm creating a scraper bot with telepot and selenium and when i get the text data that i need to send with the telegram bot it is unreadabl, because it contains unicode-escape characters (emoji) in a wrong format like: "hi I like this…
Leonardo Scotti
  • 905
  • 3
  • 20
-3
votes
1 answer

Migrating from Python 2 to Python 3

I am trying to migrate project from Python 2 to Python 3. For this I used 2to3.exe. It made most of the things correct. But my real problem is : 1. Data is stored by Python 2 Code. This data is very huge and I can't change it. 2. While reading this…
-3
votes
2 answers

How to pass non-latin string to url parameter in django?

Using django 1.7 and python 2.7, in a views I have: page = 0 sex = [u'\u0632\u0646'] #sex = زن url = "/result/%s/%d" % (sex, page) return HttpResponseRedirect(url) Which needs to return: /result/زن/0 However the resulting url turns out to…
supermario
  • 2,237
  • 3
  • 28
  • 53
-4
votes
1 answer

Remove words in string if it contains \u in python?

I want to remove words in string if it contains \u in python? ex: string ="\uf064thickness cfoutside\uf0d7\uf03a\uf03d TC2019 45TRCMat" The final output should be like this. "TC2019 45TRCMat" After removing all of the words if it contains \u.
domahc
  • 229
  • 1
  • 6
-4
votes
2 answers

AttributeError: 'unicode' object has no attribute XXX

I'm trying to use pipl. I want to get the info from a mail and save it into a Excel file. from piplapis.search import SearchAPIRequest from piplapis.search import SearchAPIError from openpyxl import load_workbook request =…
SoftTimur
  • 8,904
  • 23
  • 106
  • 212
-5
votes
1 answer

Why unicode elements of lists would be hide?

If I want to display Unicode elements as string correctly, why should I do, in the English language?
hamed baziyad
  • 1,364
  • 3
  • 19
  • 31
1 2 3
63
64