cleaner way to write this?

John Salerno johnjsal at
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()
             return db_name

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.


More information about the Python-list mailing list