The text file contains Python codes.
My task is to write a program which checks if it could run in python. I cannot find out how to check if the lines are correct in python.
I can read lines from the text file, but still don't know how to decide if the current line would run without any error messages. If it would run the program prints True
, else False
.
lst=[]
with open("be.txt","r") as be:
for line in be:
lst.append(line.strip("\n"))
For example: A line is: "for i in range(8:
"
The result should be False
, because this ")" is missing.