To set default encoding to utf-8 in python

#!/usr/bin/env python                                                                                                   
#! -*- coding: utf-8 -*-                                                                                                
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

def execute(fname):
   io = open(fname)
   for l in io:
       print l


if __name__ == '__main__':
   fname = sys.argv[1]
   execute(fname)

Recommended Posts

To set default encoding to utf-8 in python
Change python default encoding to utf-8
Encoding judgment in Python
UTF8 text processing in python
Base64 encoding images in Python 3
To flush stdout in Python
Login to website in Python
Get environment variables in Python, otherwise set default values
Set constructor keyworded arguments to mock attributes in Python
[Python] Convert Shift_JIS to UTF-8
Speech to speech in python [text to speech]
How to develop in Python
Post to Slack in Python
Set python test in jenkins
How to import Python library set up in EFS to Lambda
[Python] How to do PCA in Python
Convert markdown to PDF in Python
How to collect images in Python
Set opset to embed in ONNX
How to use SQLite in Python
Open UTF-8 with BOM in Python
In the python command python points to python3.8
Try to calculate Trace in Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
6 ways to string objects in Python
How to use PubChem in Python
How to handle Japanese in Python
An alternative to `pause` in Python
[Raspberry Pi] Changed Python default to Python3
Things to watch out for when using default arguments in Python
What I was addicted to with json.dumps in Python base64 encoding
Python encoding
Precautions when giving default values to arguments in Python function definitions
I tried to implement PLSA in Python
[Introduction to Python] How to use class in Python?
Try logging in to qiita with Python
Install Pyaudio to play wave in python
How to access environment variables in Python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
How to dynamically define variables in Python
How to do R chartr () in Python
Pin current directory to script directory in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Send email to multiple recipients in Python (Python 3)
Convert psd file to png in Python
Sample script to trap signals in Python
Decorator to avoid UnicodeEncodeError in Python 3 print ()
How to work with BigQuery in Python
Associate the table set in python models.py
Log in to Slack using requests in Python
Set default values before commit in sqlalchemy.orm
How to get a stacktrace in python
How to display multiplication table in python
Easy way to use Wikipedia in Python
How to extract polygon area in Python
How to check opencv version in python
I tried to implement ADALINE in Python