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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 🙁