Trying to run EX 20, but the output gets all wonky when I do. I have also gone back and looked at my code and rewritten it multiple times, but it keeps spitting out the same thing. Google searches for weird output errors have said that it might be an Encoding issue, but in Atom I am using the recommended UTF-8 encoding.
Any help is greatly appreciated!
Here is my code:
from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
def rewind(f):
f.seek(0)
def print_a_line(line_count, f):
print(line_count, f.readline())
current_file = open(input_file, encoding=‘utf-16-sig’)
print(“First let’s print the while file:\n”)
print_all(current_file)
print(“Now let’s rewind, kind of like a tape.”)
rewind(current_file)
print(“Let’s print three lines:”)
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
Here is my output in powershell:
First let’s print the while file:
ÿþ1
2
3
4
Now let’s rewind, kind of like a tape.
Let’s print three lines:
1 ÿþ1
2
3 2
my test.txt file is just
1
2
3
4
Thanks in advance!