adding ex23 & 24
This commit is contained in:
parent
93e9083608
commit
402d63519d
5 changed files with 174 additions and 9 deletions
31
sami/learn-python-the-hard-way/ex23.py
Normal file
31
sami/learn-python-the-hard-way/ex23.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue