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
-2
votes
2 answers

Insert enter marks before the selected word

I need to insert line breaks (enter marks) between a string before each new word starts. String: test (n) trial, experiment, check run (v) race, rush speed (n) race, sprint, rush, dash, zoom Expected: test (n) trial, experiment, check run (v)…
shantanuo
  • 31,689
  • 78
  • 245
  • 403
-2
votes
3 answers

How to handle UnicodeDecodeError

str1="khloé kardashian" Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128) how to encode it in perfect way. I am trying…
Raj
  • 368
  • 1
  • 5
  • 17
-2
votes
1 answer

Unicode conversion issue while using API gateway

The following URL works as expected and returns "null". https://zga2tn1wgd.execute-api.us-east-1.amazonaws.com/mycall?url=https://mr.wikipedia.org/s/4jp4 But the same page, with unicode string instead of ascii string, throws an…
shantanuo
  • 31,689
  • 78
  • 245
  • 403
-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
  • 11,937
  • 17
  • 63
  • 152
-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
  • 689
  • 2
  • 11
  • 23
-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
  • 47
  • 1
  • 3
  • 10
-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
  • 929
  • 3
  • 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
  • 917
  • 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
  • 20,175
  • 35
  • 77
  • 104
-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

How to convert Unicode codepoint to UTF-8 Hex Bytes?

Given a list of all emojis, I need to convert unicode codepoint to UTF-8 hex bytes programmatically. For example: Take this emoji: https://unicode-table.com/en/1F606/ and convert 1F606 to F0 9F 98 86 Please provide code examples in python or…
-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

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
  • 5,630
  • 38
  • 140
  • 292
-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,625
  • 4
  • 38
  • 58
-4
votes
1 answer

A telegram bot to make purchase from telegram bot shop

I recently found a a bot shop on telegram selling digital accounts and stuff... but everytime i try to purchase it gets sold.. kind of like a sale.. so what are the ways to quickly buy it before anyone else does? is it possible to create a bot for…
1 2 3
70
71