cleaner way to write this?

Farshid Lashkari no at spam.com
Wed Oct 25 14:28:04 EDT 2006


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

Yeah, I think the second way is usually used by people who are more 
accustomed to programming in C, since they need to initialize variables. 
Your way is probably more Pythonic though.

-Farshid



More information about the Python-list mailing list