I was experimenting with simple code to see how read() behaves on text files. So I made a simple txt file with the following:
AB
BA
Tried to output to console the fist 2 characters.
With encoding set to "ansi" to both txt file and open() the output is correct.
With encoding set to "utf-8" to both txt file and open() the output is A.
With encoding set to "utf-8" to txt file and open() set to default the output is ο».
What is going on ? locale.getpreferredencoding() returns cp1253. Could be that ο» character's messing with my utf-8 encoding? How can I get rid of it?
My code:
current_dir = "some_directory" #doesn't really matter
file_name = "name_of_text.txt"
full_path = current_dir+file_name
file_mode = "rt"
f = open(full_path,mode = file_mode) # add encoding = "utf_8" or "ansi" to replicate
reader = f.read(2)
print(reader)
f.close()