这是比萨饼,即食食品和咖喱的食物计时器。解释器返回一堆语法错误。有人可以帮我清理代码吗?我很感激。
class ItemDelegate(QtGui.QStyledItemDelegate):
def createEditor(self, parent, option, index):
item_data = str(index.data().toString())
editor = Widget(item_data.split('|'), parent=parent)
return editor
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
答案 0 :(得分:1)
你有一个班级,但你不称呼它。此外,如果try
下降,则需要使用except
。如果您想使用exit()
pacakge的sys
功能,则应将其与sys.exit()
一起使用。
这可以按你的意愿运作:
import os # Native commands
import time #Timer
import sys
choice = "" # Defining
p = "pizza" # Defining
r = "readymeal" # Defining
c = "curry" # Defining
class Main:
# Check something = True/False
def UserInput(self):
try:
choice = raw_input("Which food? ")
if choice == p:
print "Alarm Set "
time.sleep(900) # 15 Min
os.system("start Alien_Siren.mp3") # Notification
elif choice == r:
print "Alarm Set"
time.sleep(420) # 7 Min
os.system("start Alien_Siren.mp3") # Notification
elif choice == c:
print "Alarm Set"
time.sleep(420)
elif choice == "pizza and readymeal": # Must type pizza and readymeal
print "Alarm Set"
time.sleep(1320) # 22 Min
elif choice == "exit": # Exit
sys.exit()
elif choice != p or choice !=r or choice !=c:
print "Invalid choice"
sys.exit()
except:
# put whatever you want here
pass
m = Main()
m.UserInput()
答案 1 :(得分:0)
你使用本地翻译吗?我建议使用Ipython(Jupyter Notebook)来调试语法错误:http://jupyter.org/。