PyWart: The problem with "print"
Rick Johnson
rantingrickjohnson at gmail.com
Mon Jun 3 23:53:35 EDT 2013
On Monday, June 3, 2013 10:16:13 PM UTC-5, Vito De Tullio wrote:
> Rick Johnson wrote:
> > Take your
> > standard yes/no/cancel dialog, i would expect it to return
> > True|False|None respectively,
> you clearly mean True / False / FileNotFound.
No, i clearly meant what i said :-). FileDialogs only return
one of two values; either a valid path or a value
representing "failure". I suppose FileNotFound is a custom
exception? That will work however i wonder if exception
handling is overkill for this?
try:
path = filedialog.open("path")
except FileNotFound:
return
do_something(path)
As opposed to:
path = filedialog.open("path")
if path:
do_something(path)
Or, if Python was really cool!
if filedialog.open("path") as path:
do_something(path)
However, i think True|False|None is the best return values
for a yes|no|cancel choice. Consider:
result = yesnocancel("save changes?")
if result:
# Try to save changes and close.
if self.fileSave():
app.close()
else:
show_error()
elif result is False:
# Close without saving changes.
app.close()
else:
# Canceled: Do nothing.
return
More information about the Python-list
mailing list