(SOLVED) Ex23.py - TypeError 'encoding'

Greetings all,

I’ve exhausted my “Google-fu” options and thought that someone here could help me understand whats happening:

I’m running the Ex23.py script on a Raspberry Pi with a Kali image on it and getting the following error:

Traceback (most recent call last):
File “ex23.py”, line 21, in
languages = open(“languages.txt”, encoding=“utf-8”)
TypeError: ‘encoding’ is an invalid keyword argument for this function

Now the way I’m interpreting that is that Python is saying that the “encoding” keyword isn’t a valid argument for the “open” function.

Pydoc says it should work and when I ran the same script on another Linux mint box, it worked so, I’m just wondering why it worked on one vs the other.

Any thought’s or insights would are greatly appreciated.

Thx!

Ryan

Could you inadvertently be running Python 2? open didn’t have the encoding parameter in Python 2.
You can find out by doing python --version on the command line.

This might help set the default too depending on which Pi you’re running:

Morning Florian,

You are correct sir! Just a complete “doh” moment when I ran it on the Pi apparently.

I’d been working with this exercise over a period of a few days. Apparently on one of those days I added a shebang to the script that was on the Mint box and it was correctly invoking python3 when I ran it.

Thanks for the insights…greatly appreciated.

2 Likes

Thanks for the link GPK…also, greatly appreciated!

A free service run by Zed A. Shaw for learncodethehardway.org.