1

My code:

def getAppHistory(self): path = self.APP_STORAGE + "\\history.dat" if os.path.exists(path): hist_file = open(path, "r") hist_data = hist_file.read() else: hist_file = open(path, "w") hist_data = "[200, \"Empty\", \"You have no device history!\", \"self.Void\"]" hist_file.write(hist_data) self.conn_menu.append(eval(hist_data)) 

The error:

 File "C:\Users\Judge\Desktop\Lulz\Lulz.py", line 113, in getAppHistory self.conn_menu.append(eval(hist_data)) File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing 

2 Answers 2

2

This could happen if the hist_file exists but is empty

You should print hist_data before you try to eval it so you can see for sure

Also: Make sure you understand the dangers of using eval

Sign up to request clarification or add additional context in comments.

Comments

0

As gnibbler has explained, this can occur if a file (in this case "history.dat") already exists but is empty.

Test ran it in python v3 IDLE using:

import os def getAppHistory(): path = "C:/test/history.dat" if os.path.exists(path): hist_file = open(path, "r") hist_data = hist_file.read() else: hist_file = open(path, "w") hist_data = "[200, \"Empty\", \"You have no device history!\", \"self.Void\"]" hist_file.write(hist_data) print(eval(hist_data)) hist_file.close() 

Ran perfectly on the first go; however when i manually removed the lines and made the file empty, it gave the same error you are getting. Again, as gnibbler pointed out, first see what flaws and/or possible down points "eval" has to your project/work..

Comments