Linked Questions
44 questions linked to/from How to set sys.stdout encoding in Python 3?
4
votes
5
answers
8k
views
Printing to stdout with encoding in Python 3 [duplicate]
I have a Python 3 program that reads some strings from a Windows-1252 encoded file:
with open(file, 'r', encoding="cp1252") as file_with_strings:
# save some strings
Which I later want to write ...
0
votes
1
answer
1k
views
How do I specify the encoding in an print() statement? [duplicate]
How do I specify the encoding during a print() statement?
2
votes
1
answer
549
views
Python CGI script wont print Hebrew on Linux [duplicate]
I cannot get python CGI to print Hebrew characters to an html webpage on Linux. This is a script which demonstrates the problem:
#!/usr/bin/python3
print('Content-Type: text/html; charset=utf-8\n\n')
...
0
votes
1
answer
451
views
Setting stdout UTF8 encoding with Python3 [duplicate]
I have carefully read answers from Setting the correct encoding when piping stdout in Python but:
the solution export PYTHONIOENCODING=utf8 does not work if you're not calling the process yourself. ...
2
votes
0
answers
36
views
Using Python log lib, how to set the locale of the console StreamHandler? [duplicate]
In my Python code I log to stderr and to a file with this configuration:
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s : %(name)s - %(levelname)s - %(message)s",
...
377
votes
13
answers
278k
views
Setting the correct encoding when piping stdout in Python
When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:
# -*- coding: utf-8 -*-
print u"åäö"
will work ...
103
votes
4
answers
32k
views
UnicodeDecodeError when redirecting to file
I run this snippet twice, in the Ubuntu terminal (encoding set to utf-8), once with ./test.py and then with ./test.py >out.txt:
uni = u"\u001A\u0BC3\u1451\U0001D10C"
print uni
Without redirection ...
35
votes
6
answers
62k
views
How to print utf-8 to console with Python 3.4 (Windows 8)?
I'm trying to print utf-8 card symbols (♠,♥,♦︎︎,♣) from a python module to a windows console. The console that I'm using is git bash and I'm using console2 as a front-end. I've tried/read a number of ...
19
votes
4
answers
35k
views
PySpark — UnicodeEncodeError: 'ascii' codec can't encode character
Loading a dataframe with foreign characters (åäö) into Spark using spark.read.csv, with encoding='utf-8' and trying to do a simple show().
>>> df.show()
Traceback (most recent call last):
...
17
votes
4
answers
12k
views
Unicode error when outputting python script output to file
This is the code:
print '"' + title.decode('utf-8', errors='ignore') + '",' \
' "' + title.decode('utf-8', errors='ignore') + '", ' \
'"' + desc.decode('utf-8', errors='ignore') + '")'
...
11
votes
1
answer
4k
views
Output binary data from CGI in Python 3
This question is related to this one. I was having no problems while printing raw binary data from a CGI script in Python 2, for example:
#!/usr/bin/env python2
import os
if __name__ == '__main__':
...
10
votes
4
answers
3k
views
Python print Unicode string via 'Git Bash' gets 'UnicodeEncodeError'
in test.py i have
print('Привет мир')
with cmd worked as normal
> python test.py
?????? ???
with Git Bash got error
$ python test.py
Traceback (most recent call last):
File "test.py", line 2, ...
8
votes
3
answers
4k
views
How to encode all logged messages as utf-8 in Python
I have a little logger function that returns potentially two handlers to log to a RotatingFileHandler and sys.stdout simultaneously.
import os, logging, sys
from logging.handlers import ...
5
votes
2
answers
5k
views
Transmitting a pickled object output between python scripts through a subprocess.communicate
I have two python scripts:object_generator.py which pickles a given object and prints it. Another script object_consumer.py picks the output of the first script through a subprocess.communicate and ...
11
votes
3
answers
1k
views
Sublime Text console not showing lines with accents
In Sublime Text 2 and 3, the console output doesn't show the lines with accents on it:
I'm using Tools > Build in vanilla Sublime in Windows with automatic Build System to execute it....