Linked Questions
43 questions linked to/from Working with UTF-8 encoding in Python source
326
votes
7
answers
469k
views
"SyntaxError: Non-ASCII character ..." or "SyntaxError: Non-UTF-8 code starting with ..." trying to use non-ASCII text in a Python script
I tried this code in Python 2:
def NewFunction():
return '£'
But I get an error message that says:
SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www....
0
votes
2
answers
156
views
vs code encoding conflict between Output and matplotlib for french accents [duplicate]
when I prefix my .py file using utf-8 or Latin-1 I always get bad charcacters in OUTPUT or in matplotlib figure text.
Post 'Working with UTF-8 encoding in Python source' does not answer my question ...
181
votes
6
answers
99k
views
Correct way to define Python source code encoding
PEP 263 defines how to declare Python source code encoding. Normally, the first 2 lines of a Python file should start with:
#!/usr/bin/python
# -*- coding: <encoding name> -*-
But I have seen a ...
165
votes
4
answers
110k
views
Python: Using .format() on a Unicode-escaped string
I am using Python 2.6.5. My code requires the use of the "more than or equal to" sign. Here it goes:
>>> s = u'\u2265'
>>> print s
>>> ≥
>>> print "{0}".format(s)...
5
votes
3
answers
33k
views
brackets around print in python [duplicate]
I have this line of code in python
print 'hello world'
against
print ('hello world')
can someone tell me the difference between the two?
I used it in a a simple code
var = 3
if var > 2:
...
6
votes
3
answers
28k
views
Reading non-ASCII characters from a text file
I'm using python 2.7. I've tried many things like codecs but didn't work. How can I fix this.
myfile.txt
wörd
My code
f = open('myfile.txt','r')
for line in f:
print line
f.close()
Output
s\...
6
votes
3
answers
19k
views
"SyntaxError: Non-ASCII character" in running Python code
Im starting with python and when i use the interpreter and run this code:
>>>peliculas = ["movie1", "movie2", "movie3", "movie4"]
>>>print(peliculas[1])
when i use Pycharm IDE it ...
7
votes
3
answers
8k
views
Non-ASCII character '\x90' executing pserve on windows inside virtualenv
Question: How can i solve no-ascii character error executing pserve on virtualenv in windows?
Description: I'm trying to execute pserve (pyllons/pyramid development web server) inside a virtualenv on ...
4
votes
2
answers
2k
views
Defining unicode variables in Python
Recently, I have been reading about the Python source code encoding, especially PEP 263 and PEP 3120.
I have the following code:
# coding:utf-8
s = 'abc∂´ƒ©'
ƒ = 'My name is'
ß = '˚ß˙ˆ†ˆ∆ ßå®åø©ˆ'
...
0
votes
1
answer
14k
views
utf-8 encoding and greek characters [duplicate]
While I managed to get all the data that I need as well as save it on a cv file, the output I get is in UTF-8 format, which is normal(correct me If I'm wrong)
TBH I've already "played" with the ....
1
vote
2
answers
5k
views
Python 3 character encoding issue
i am selecting values from a MySQL // Maria DB that contains latin1 charset with latin1_swedish_ci collation. There are possible characters from different European language as Spanish ñ, German ä or ...
2
votes
2
answers
5k
views
Writing CSV file with umlauts causing "UnicodeEncodeError: 'ascii' codec can't encode character"
I am trying to write characters with double dots (umlauts) such as ä, ö and Ö. I am able to write it to the file with data.encode("utf-8") but the result b'\xc3\xa4\xc3\xa4\xc3\x96' is not nice (UTF-8 ...
3
votes
1
answer
2k
views
Python: 'ascii' codec can't encode characters
I am using the following code to scrape a webpage that contains Japanese characters:
import urllib2
import bs4
import time
url = 'http://www.city.sapporo.jp/eisei/tiiki/toban.html'
pagecontent = ...
2
votes
2
answers
3k
views
Pymongo $regexMatch invalid flag in regex options: u
Using PyMongo 3.10.1, MongoDB 4.2 the aggregation below, using $group with $regexMatch works OK on command line:
db.accounts.aggregate([
{'$lookup': {'from': 'users', 'localField': '_id', '...
0
votes
2
answers
4k
views
Python Syntax error: non-ASCII [duplicate]
I keep getting an error and I'm not sure on how to fix it.
The Code line:
if not len(lines) or lines[-1] == '' or lines[-1] == '▁':
lines = list(filter(lambda line: False if line == '' or line ==...