cleaner way to write this?

Steve Holden steve at holdenweb.com
Wed Oct 25 18:58:05 EDT 2006


Paul Rubin wrote:
> 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.

Of course, in 2.5 you can write

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

but frankly I think this is horrible. I suspect we'd better get used to 
it, though ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list