added python exercises
This commit is contained in:
parent
ce69011b6f
commit
e2cf1a9865
7 changed files with 208 additions and 0 deletions
32
balazs/python-the-hard-way/ex23/#notes#
Normal file
32
balazs/python-the-hard-way/ex23/#notes#
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
* Questions:
|
||||||
|
|
||||||
|
** How does the program reads the file?
|
||||||
|
readline
|
||||||
|
|
||||||
|
** How does it loops over the lines?
|
||||||
|
readline will return an empty string when no more data is available
|
||||||
|
|
||||||
|
*** https://stackoverflow.com/questions/28936140/use-readline-to-read-txt-file-python3
|
||||||
|
|
||||||
|
** Why doesnt he uses a for loop? (instead of return) -later
|
||||||
|
|
||||||
|
Good to know:
|
||||||
|
|
||||||
|
"The second method still reads the file line by line and does not load the whole file into memory, right? – nishant Nov 14 '19 at 7:24"
|
||||||
|
"@nishant correct – Ilan Kleiman Dec 15 '19 at 1:42"
|
||||||
|
|
||||||
|
|
||||||
|
** What is "with" in python? -later
|
||||||
|
|
||||||
|
** Why should I use builting python utils instead of *nix utils? -later
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* Notes:
|
||||||
|
|
||||||
|
strip: for text formatting
|
||||||
|
|
||||||
|
|
||||||
|
* Log:
|
||||||
|
|
||||||
|
Takes a long time to watch the video.
|
1
balazs/python-the-hard-way/ex23/.#notes
Symbolic link
1
balazs/python-the-hard-way/ex23/.#notes
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
user@1lnu.12786
|
25
balazs/python-the-hard-way/ex23/convertor.py
Normal file
25
balazs/python-the-hard-way/ex23/convertor.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import sys
|
||||||
|
script, input_encoding, error = sys.argv
|
||||||
|
|
||||||
|
print (sys.argv)
|
||||||
|
|
||||||
|
def main(language_file, encoding, errors):
|
||||||
|
|
||||||
|
line = language_file.readline()
|
||||||
|
print (line)
|
||||||
|
|
||||||
|
if line:
|
||||||
|
print_line(line, encoding, errors)
|
||||||
|
return main(language_file, encoding, errors)
|
||||||
|
|
||||||
|
def print_line(line, encoding, errors):
|
||||||
|
next_lang = line.strip()
|
||||||
|
raw_bytes = next_lang.encode(encoding, errors=errors)
|
||||||
|
cooked_string = raw_bytes.decode(encoding, errors=errors)
|
||||||
|
|
||||||
|
print(raw_bytes, "<===>", cooked_string)
|
||||||
|
|
||||||
|
|
||||||
|
languages = open("languages.txt", encoding="utf-8")
|
||||||
|
|
||||||
|
main(languages, input_encoding, error)
|
21
balazs/python-the-hard-way/ex23/convertor.py~
Normal file
21
balazs/python-the-hard-way/ex23/convertor.py~
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import sys
|
||||||
|
script, input_encoding, error = sys.argv
|
||||||
|
|
||||||
|
def main(language_file, encoding, errors):
|
||||||
|
line = language_file.readline()
|
||||||
|
|
||||||
|
if line:
|
||||||
|
print_line(line, encoding, errors)
|
||||||
|
return main(language_file, encoding, errors)
|
||||||
|
|
||||||
|
def print_line(line, encoding, errors):
|
||||||
|
next_lang = line.strip()
|
||||||
|
raw_bytes = next_lang.encode(encoding, errors=errors)
|
||||||
|
cooked_string = raw_bytes.decode(encoding, errors=errors)
|
||||||
|
|
||||||
|
print(raw_bytes, "<===>", cooked_string)
|
||||||
|
|
||||||
|
|
||||||
|
languages = open("languages.txt", encoding="utf-8")
|
||||||
|
|
||||||
|
main(languages, input_encoding, error)
|
97
balazs/python-the-hard-way/ex23/languages.txt
Normal file
97
balazs/python-the-hard-way/ex23/languages.txt
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
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
|
||||||
|
文言
|
||||||
|
吴语
|
||||||
|
ייִדיש
|
||||||
|
中文
|
32
balazs/python-the-hard-way/ex23/notes
Normal file
32
balazs/python-the-hard-way/ex23/notes
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
* Questions:
|
||||||
|
|
||||||
|
** How does the program reads the file?
|
||||||
|
readline
|
||||||
|
|
||||||
|
** How does it loops over the lines?
|
||||||
|
readline will return an empty string when no more data is available
|
||||||
|
|
||||||
|
*** https://stackoverflow.com/questions/28936140/use-readline-to-read-txt-file-python3
|
||||||
|
|
||||||
|
** Why doesnt he uses a for loop? (instead of return) -later
|
||||||
|
|
||||||
|
Good to know:
|
||||||
|
|
||||||
|
"The second method still reads the file line by line and does not load the whole file into memory, right? – nishant Nov 14 '19 at 7:24"
|
||||||
|
"@nishant correct – Ilan Kleiman Dec 15 '19 at 1:42"
|
||||||
|
|
||||||
|
|
||||||
|
** What is "with" in python? -later
|
||||||
|
|
||||||
|
** Why should I use builting python utils instead of *nix utils? -later
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* Notes:
|
||||||
|
|
||||||
|
strip: for text formatting
|
||||||
|
|
||||||
|
|
||||||
|
* Log:
|
||||||
|
|
||||||
|
Takes a long time to watch the video.
|
Binary file not shown.
Loading…
Reference in a new issue