Ex. 23 LPTHW help

Hi! I’m doing ex.23 of LPTHW and ran into a problem, some help would be appreciated.
Here’s the code:


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") # Unicode Transformation-8-bit

main(languages, input_encoding, error)

When I run the py file on the CMD I get some strange question marks on some languages, does someone know why?

And so on…
Thanks!

It’s a windows problem it happens on powershell and cmd where it can’t handle the encodings. You can try an alternative shell called tabby Releases · Eugeny/tabby · GitHub and download the x64.exe that’s what I did and it worked or otherwise just leave it.

2 Likes

Thank you! I’ll try it as soon as I can, hope it works.
Edit: It worked :slight_smile:

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