Python Ex.23 languages.txt file

I cannot seem to download the languages.txt file necessary to complete the exercise. I try to create a languages.txt from what is in the link to download the file, however, my file is not the same as the file shown in the video. Any ideas on how to download or create the same languages.txt file shown in the video?

You are most likely just clicking on the file in the PDF, and then it open Safari or Internet Explorer to display the file. Problem is they fail to interpret the file at utf-8 encoded and assume it’s ASCII because of the .txt ending and the configuration on the web server. What happens is then you copy-paste it and your text editor thinks it’s ASCII and gets it wrong.

All you have to do is this:

  1. Right click on the link or on this link https://learnpythonthehardway.org/python3/languages.txt
  2. Select Save As… instead of just opening it. This will save the raw file.

Then you can open it in your text editor (which works best in Atom or Visual Studio Code) and it’ll look correct. Here’s what it looks like in my Visual Studio code:

If that doesn’t work, then here’s the full contents of the file, so hopefully you can copy paste this and it’ll work:

Afrikaans
አማርኛ
Аҧсшәа
العربية
Aragonés
Arpetan
Azərbaycanca
Bamanankan
বাংলা
Bân-lâm-gú
Беларуская
Български
Boarisch
Bosanski
Буряад
Català
Чӑвашла
Čeština
Cymraeg
Dansk
Deutsch
Eesti
Ελληνικά
Español
Esperanto
فارسی
Français
Frysk
Gaelg
Gàidhlig
Galego
한국어
Հայերեն
हिन्दी
Hrvatski
Ido
Interlingua
Italiano
עברית
ಕನ್ನಡ
Kapampangan
ქართული
Қазақша
Kreyòl ayisyen
Latgaļu
Latina
Latviešu
Lëtzebuergesch
Lietuvių
Magyar
Македонски
Malti
मराठी
მარგალური
مازِرونی
Bahasa Melayu
Монгол
Nederlands
नेपाल भाषा
日本語
Norsk bokmål
Nouormand
Occitan
Oʻzbekcha/ўзбекча
ਪੰਜਾਬੀ
پنجابی
پښتو
Plattdüütsch
Polski
Português
Română
Romani
Русский
Seeltersk
Shqip
Simple English
Slovenčina
کوردیی ناوەندی
Српски / srpski
Suomi
Svenska
Tagalog
தமிழ்
ภาษาไทย
Taqbaylit
Татарча/tatarça
తెలుగు
Тоҷикӣ
Türkçe
Українська
اردو
Tiếng Việt
Võro
文言
吴语
ייִדיש
中文
3 Likes

Hi, I did all you said. Still doesn’t work…

Hi @kcoldevin, can you be more specific? What exactly doesn’t work for you?

Hi Florian,

I solved it. Too much indentation in my script.


Pleas help:
script, input_encoding, error = sys.argv
ValueError: not enough values to unpack (expected 3, got 1)

The script needs two command line arguments: python3 ex23.py ENCODING ERROR. Take a look at the example runs in the book for possible values.

it’s exactly like in the book… doesn’t work…

It’s not about the script, it’s about how you run it.
You are doing

python3 ex23.py

but you need to add two arguments to the call, for example:

python3 ex23.py utf-8 strict
1 Like

Thank you so much, now it works.

It was very helpful thanks!

Can you take a look at the exercise and maybe tell my why you didn’t see you had to run it this way? It’s a very common error and I can’t seem to write anything that stops people from making it.

1 Like

Hi Zed,

I’m going through Exercise 23 now, and I thought I might offer a reply to this, as (not in this exercise, but in others) I had trouble understanding that my issue was the command line. I think the issue is, at its root, that in the first exercises in the book, the ‘What You Should See’ section, though it does include the command line, is presented just as that: what you should see returned once you have executed the command line. Even by Ex 23, I forget at times that ‘What You Should See’ also includes the command line. I’m not sure if perhaps somehow splitting up the command line and what is returned (which is of course not how the Terminal actually looks), or perhaps renaming the section of each chapter from ‘What You Should See’ to something more like ‘The Terminal Window’ or ‘The Command Line and What You Should See’. For me personally, again, the issue was the psychological categorization I formed early on, where in my mind ‘What You Should See’ did not contain any information about what I had to put in, but only what would be returned; however this could be overcome might help out.

Another aspect of Exercise 23 that I found difficult (eventually finding this thread) is that you write, “you’ll need to download a text file that I’ve written named languages.txt (https://learnpythonthehardway.org/python3/languages.txt).” In ‘Initial Research’, you repeat the term ‘download’. For me at least, what I attempted to do was to type that URL in and visit the webpage. Upon doing so, right-clicking on the page I was able to Save As…; but I was only able to save it as a .webarchive file, and so instead copied and pasted the text (which, as I found out above, is in ASCII, not UTF-8) into a new .txt file. I then attempted to make my Terminal display UTF-8 for a few hours, and nothing worked (and getting into talk about .inputrc files and things like that, I was in way over my head anyway), and it was only after coming to this page (and watching the video for this exercise) that I realized that the issue was not the Terminal, but the original file. All this to say that ‘download’ the file is perhaps a bit too vague to be of use to someone who has not downloaded a webpage from the internet.

I hope this feedback is helpful; thank you for your work to help us all understand, learn, and be able to actually use Python.

Regards,

Tony

Hey Tony,

There’s all kinds of weird problems with doing that as a text file, not including that browsers try to “fix” it by converting it to odd encodings depending on where the person is from.

But, are you telling me that you right click on that link above, and then your browser does not make a languages.txt file? It makes a .webarchive file?

I think what’s happening then is you are right clicking on the page and not the link. So, let’s say you have this link here:

https://learnpythonthehardway.org/python3/languages.txt

And then, let’s say I have this text here:

Green eels taste purple.

Now, if you hover your mouse over the actual blue text of the link (such that your mouse pointer turns into a hand with a pointing finger) then a right click will give you a Save As… that saves only the languages.txt file.

The misstep here is if you hovered over “Green eels taste purple” and did the exact same thing and did a right click and selected Save As… you get some kind of webarchive. In fact, the menu should say “Save Page As…” when you right-click on “Green eels taste purple”.

What’s happening is one context menu (that’s what happens when you right-click on things, a menu for that context of that thing) is for a link, and another (Green eels taste purple) is for the whole page.

Can you try that out and confirm I’m right this is what you did?

Hey Zed,

That was in fact one issue I had - but it was slightly different. Reading through the print book at least, what I did was type the URL given into the web browser, and what came up was the page displaying the text file (or rather, what is in the text file, but, I would imagine, in ASCII). As you mention, I suppose this is my browser (Safari) trying to ‘fix’ the file. So when I opened the context menu for that page, it’s true, I could only save it as a .webarchive file, which did not help when I tried to open it up in Atom. I wish that were easier! But as you say, there is perhaps no way around that in particular.

But the issue that I faced, rather, was that, using the instructions given in the book, the only way I could see to make use of the URL was to type it in and get to the webpage. So in that case, I didn’t have the opportunity to find the link that you display here. That is, without being given the link, the book provides no way to access the file. I’m not sure that’s entirely clear, but what I mean is that it seems what needs to be done is to have the hyperlink displayed on a webpage (like here) and then to right-click on it; but there is no path from the printed book to a page that contains the link, and so I just went straight to the page accessed via the link, and once on that page, your only options are to access the context menu (thanks for that terminology) for the whole page, or to copy the text as it is displayed. I tried the latter - and, inevitably, could not go any further, as I was copying the text in a different encoding.

So, in short, what you say is correct, to an extent - but the more fundamental issue I had was that I had no access to a link to right-click.

Let me know if I’m making sense.

Tony

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