cleaner way to write this?
Michael S
msherman77 at yahoo.com
Wed Oct 25 16:53:59 EDT 2006
How about this?
def create_db_name(self):
dlg = wx.TextEntryDialog(self.frame, 'Enter a
database name:',
'Create New
Database')
db_name = None #or db_name = ""
if dlg.ShowModal() == wx.ID_OK:
db_name = dlg.GetValue()
dlg.Destroy()
return db_name
--- John Salerno <johnjsal at NOSPAMgmail.com> wrote:
> Hi guys. I'm looking for a nicer, more compact way
> of writing this code.
> It doesn't have to be anything fancy, just something
> without the
> duplication and preferably only one return
> statement.
>
> def create_db_name(self):
> dlg = wx.TextEntryDialog(self.frame, 'Enter
> a database name:',
> 'Create New
> Database')
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> dlg.Destroy()
> return db_name
> else:
> dlg.Destroy()
> return
>
> One problem is that if "Cancel" is pressed, I can't
> return anything.
> Another problem is that the dialog must be
> destroyed, so that has to
> come before any return statements.
>
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list