cleaner way to write this?

Paul Rubin http
Wed Oct 25 20:24:51 CEST 2006


John Salerno <johnjsal at NOSPAMgmail.com> writes:
>          if dlg.ShowModal() == wx.ID_OK:
>              db_name = dlg.GetValue()
>              dlg.Destroy()
>              return db_name
>          else:
>              dlg.Destroy()
>              return

I like

    if dlg.ShowModal() == wx.ID_OK:
         db_name = dlg.GetValue()
    else:
         db_name = None
    dlg.Destroy()
    return db_name

better than

    db_name = None
    if dlg.ShowModal() == wx.ID_OK:
         db_name = dlg.GetValue()
    dlg.Destroy()
    return db_name

but I suppose it's a matter of preference.



More information about the Python-list mailing list