Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify encoding to fileinput

Tags:

python

In Python how do I specify the encoding to fileinput.input?

I wrote

f = fileinput.input(openhook=fileinput.hook_encoded("windows-1252"))

but it doesn't work reliably. I get different results for script.py text.txt and script.py < text.txt

like image 793
Colonel Panic Avatar asked Oct 24 '12 18:10

Colonel Panic


1 Answers

This is a bug in the fileinput module, it only uses the the encoding information when reading from files, not when reading from standard input :(

like image 159
Colonel Panic Avatar answered Oct 03 '22 07:10

Colonel Panic