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

how to print '\u20ac' instead of the € in python

>>> x='\u20ac' >>> x '€' Is there a way to print the string '\u20ac' directly instead of that euro sign? (on python)
Jolly
  • 7
  • 2
-1
votes
2 answers

How do I keep only ascii and discard non-ascii, nbsp, etc while doing json.dumps

I read csv files using csv reader, and then convert it into a json file using dictionary. In doing so, I would like only letters and numbers with no non-ascii characters or nbsp. I am trying to do it like this: with open ('/file', 'rb') as…
Mr.President
  • 163
  • 1
  • 9
-1
votes
1 answer

Replacing backslash '\' in python

When trying to replace '\' in python, the data changed and give me unknown letters. i have tried string.replace, re.sub, regex_replace a = '70\123456' b = '70\123\456' a = a.replace('\\','-') b = b.replace('\\','-') Expected Result: a =…
-1
votes
1 answer

UnicodeEncodeError: 'ascii' codec can't encode character '\u2159' in position 32: ordinal not in range(128)

I am using python3 and beautifulsoup to scrape a website but i got this error. I tried to fix this using the solutions given in other answers but none solves my problem. # -*- coding: utf-8 -*- import os import locale os.environ["PYTHONIOENCODING"]…
frifin
  • 109
  • 5
-1
votes
1 answer

UnicodeDecodeError on Windows, but not when running the exact same code on Mac

I'm trying to download json data via an API. The code is as follows: import urllib.request, ssl, json context = ssl._create_unverified_context() rsbURL = "https://rsbuddy.com/exchange/summary.json" with urllib.request.urlopen(rsbURL,…
quyksilver
  • 13
  • 6
-1
votes
2 answers

Extract the £ (pound) currency symbol and the amount (56) from an html file

Extract the £ (pound) currency symbol and the amount (56) from an html file. It is printing the amount as £56 and prints the currency as Â. How can I print only 56, without the symbol? It is working fine with a $ sign. Part of the code: cost=…
-1
votes
1 answer

python reverse unicode text into readable

i believe i have similar problem to this how to convert unicode text to utf8 text readable? but i want a python 3.7 solution to it i am a complete newbie, i have some experience with python so i am trying to use it to make a script that will convert…
-1
votes
1 answer

Escape a console string containing a path with "\r" (python)

I need to send the following commands to a busybox device via a serial port: SBC1000 > setenv serverip '192.168.128.100' SBC1000 > setenv fsfile '1k\root.jffs2-128k' SBC1000 > saveenv I can escape the single quotes of the first line without a…
Phil Brooks
  • 643
  • 4
  • 8
-1
votes
1 answer

python3 UnicodeDecodeError while logging to console

I just ported my webapp to python 3. I develop in my Mac and deploy in a CentOS server. I found many UnicodeDecodeError that don't happen in my local test environment but they appear in the deployment server (of course :D ) Most of them I fixed by…
Martin Massera
  • 1,718
  • 1
  • 21
  • 47
-1
votes
2 answers

UnicodeEncodeError when concatenating text files in Python

I am a python beginner. I am trying to add(concatenate) the text from all the 8 text files into one text file to make a corpus. However, I am getting the error UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 7311: character…
-1
votes
2 answers

Printing the unicode of all the letters in a word

I'm stuck on this question: user inputs a word, program outputs the unicode of each letter in the word this is how the input statement would look: word = input("Enter a word: ") Supposing the user enters the word "Cat", the output would look like…
galaxies
  • 63
  • 7
-1
votes
1 answer

Python 3: is there any need of using unicode_escape encoding?

This link lists out some python specific encodings. One of the encoding is "unicode_escape". I am just trying to figure out, is this special encoding really needed? >>> l = r'C:\Users\userx\toot' >>> l 'C:\\Users\\userx\\toot' >>>…
-1
votes
2 answers

Trying to Read inner key, value from unicode JSON in python

I am trying to get key value from below unicode JSON is python messagejson={ u'Records': [ { u'requestParameters': {u'sourceIPAddress': u'113.112.10.06'}, u'sql': {u'configurationId': u'note', u'object': {u'eTag': u'ed3645fa5ee', u'sequencer':…
Charan
  • 46
  • 1
  • 10
-1
votes
1 answer

python convert English emoji to string

I have the following text: / As I understand this is an English emoji, so I want to make it to: wife / mama So I can use my lang_detector which not recognize this text. Thanks.
Sion C
  • 439
  • 2
  • 14
-1
votes
1 answer

Python 2.7 reads encoded text file as code rather than text. (Fixed with io module)

I have a text file (*.txt) which displays as plain text when opened in notepad. When i attempt to read the file into python: with open(Working_File,'r') as WorkTXT: WorkTXT_Lines = WorkTXT.readlines() WorkTXT.close() My script then fails…