cleaner way to write this?

John Salerno johnjsal at NOSPAMgmail.com
Wed Oct 25 15:13:26 EDT 2006


Paul Rubin wrote:

> Oh, I see.  You really want something like repeat...while, which Python
> doesn't have.  Anyway I start to prefer something like (untested):
> 
>      def create_db_name(self):
>          try:
>             while True:
>                dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',
>                                        'Create New Database')
>                if dlg.ShowModal() != wx.ID_OK:
>                    return None
>                db_name = dlg.GetValue()
>                if db_name:
>                    return db_name
>                pop_up_error_dialog("please enter a value or press cancel")
>          finally:
>             dlg.Destroy()

Interesting. Some variation of this might suit me, but I think one other 
problem I'm having is that the ShowModal() method returns whenever a 
button is pressed, so even if OK is pressed with an empty string in the 
box, the dialog disappears and returns an "OK" value. I'll have to check 
in the wxpython group on how to handle this one, I think.



More information about the Python-list mailing list