I use raise
function in python 2.7 as a way to stop further code being executed, without exiting, when a condition is not met. This is shown in example below:
from Tkinter import *
import tkMessageBox
def foo():
a = 3
if a == 2:
tkMessageBox.showinfo('Hello', 'Yup yup yup')
else:
tkMessageBox.showinfo('Hello', 'My bad!')
raise
tkMessageBox.showinfo('Further code' ,"You shouldn't see me if a is not 2")
app = Tk()
app.title("ABC")
app.geometry()
filetype_fasta = [('fasta files', '*.fasta'), ('All files', '*.*')]
button_templ = Button(app, text = 'Click me', width =6, command = foo)
button_templ.grid(row = 3, column = 2)
app.mainloop()
It works fine for a complicated script I have. My question is this - Is there any potential problem, that I should be aware of, in using raise
this way? If yes, is there a better/common method to do the same thing?
Edit: Example changed to demonstrate the idea better.