0

I am attempting to learn python 3 and there is an exercise in the book that requires us to supply a filename on the command line when invoking the script. However, I am getting a syntax error and I cant figure out what I am doing wrong.

The environment: Windows 10 laptop running Python 3.8.0 x64 bit

The script:

from sys import argv

script, filename = argv

txt = open(filename)

print("Here's your file %r" % filename)
print(txt.read())

print("Type the filename again: ")
file_again = input("> ")

txt_again = open(file_again)

print txt_again.read()

The commandline input:

PS E:\~Python Scripts> python .\ex15.py ex15_sample.txt  

The error:

    PS E:\~Python Scripts> python .\ex15.py ex15_sample.txt                                                                   File ".\ex15.py", line 15
    print txt_again.read()
          ^
SyntaxError: invalid syntax

Thanks in advance!

0 Answers0