(Python 3.x)So I keep getting a syntax error when reading a file. I've had this problem for a while now. I've been working on other parts of the program so far(not shown), but can't solve this syntax error. I am very confused. I feel guilty posting about a syntax error but I am out of ideas.
Here is the error: Syntax Error: unexpected EOF while parsing: , line 0, pos 0 @ line 8
Code:
def main():
filename = 'p4input.txt'
infile = open(filename, "r")
command = 0
while command != 3 and command < 3:
command = eval(infile.readline()) #Problem here
convert = eval(infile.readline())
print(command)
print(convert)
print("done")
main()
The input file (p4input.txt) Has the following data:
2
534
1
1101
Complete traceback:
Traceback (most recent call last):
File "C:/Users/Ambrin/Desktop/CS 115/TESTER.py", line 16, in <module>
main()
File "C:/Users/Ambrin/Desktop/CS 115/TESTER.py", line 8, in <module>
command = eval(infile.readline())
File "<string>", line 0, in ?
Syntax Error: unexpected EOF while parsing: <string>, line 0, pos 0
eval(andexec) should generally be avoided because they can be a security risk. For details, please see Eval really is dangerous by SO veteran Ned Batchelder.