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
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 :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With