cleaner way to write this?

John Salerno johnjsal at NOSPAMgmail.com
Wed Oct 25 20:17:24 CEST 2006


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.



More information about the Python-list mailing list