Exercise 23 - Dissecting the Output, utf8 really needed?


#1

Hi there, so I wrote up my code for Exercise 23 as shown here: https://pastebin.com/7UnC7y4n

The exercise tells me to run the script in the console like this:

python ex23.py utf-8 strict

Now we need to type “utf-8 strict” to satisfy the command requirements, however, language variable is set to UTF-8 as shown:

language = open(“languages.txt”, encoding=“utf-8”)

Do we need to actually set the encoding to UTF-8 in the command line if its already set to UTF-8?


#2

Either you have the code wrong or I do. That parameter is supposed to go to the open call as an encoding. Take a look again.


#3

Hey there Zed! Thanks for replying, this is the snippet of the Chapter: https://i.imgur.com/m02PJ0J.png

As you can see from your screenshot, you type in the console “python3.6 ex23.py utf-8 strict”

I have to add the " utf-8" and “strict” at the end to satify the number of arguments required but im asking if it is needed


#4

Crazy, yep that looks like a bug. Do you think you can fix it? What would you have to do?


#5

Hmm, what is the bug though? or what is exactly wrong in your opinion? Since it is outputting how it should be. I can take a shot at the fix but what do you think is the problem and what needs to be resolved?


#6

I believe that the encoding you give on the command line isn’t being passed to the open call. I’ll have to triple check but that’s what I see. Basically the “utf-8” inside open should be something like sys.argv[1].


#7

Ah okay, is it possible you can post the new code I have to type again if you have the time?


#8

Ehhhhhh, I’d say it’s time to move on from 23. Don’t let it bog you down.