[Tutor] improvement of if - else code
Norman Khine
norman at khine.net
Thu Jun 4 19:36:34 CEST 2009
Thanks
On Thu, Jun 4, 2009 at 7:34 PM, vince spicer <vinces1979 at gmail.com> wrote:
> you could assign loop variable
>
> @staticmethod
> def get_form(address=None, postcode=None, town=None, phone=None,
> fax=None,
> freephone=None, address_country=None, address_region=None,
> address_county=None, hotel=None):
> context = get_context()
> root = context.root
> # List authorized countries
>
> loopvar = root.get_active_countries(context) if hotel else
> root.get_authorized_countries(context)
>
> countries = [ {'name': y, 'title': x, 'selected': y ==
> address_country} for x, y in loopvar ]
>
>
>
>
> On Thu, Jun 4, 2009 at 11:25 AM, Norman Khine <norman at khine.net> wrote:
>>
>> Hello,
>> Is there a better way to write this:
>>
>> @staticmethod
>> def get_form(address=None, postcode=None, town=None, phone=None,
>> fax=None,
>> freephone=None, address_country=None, address_region=None,
>> address_county=None, hotel=None):
>> context = get_context()
>> root = context.root
>> # List authorized countries
>> if hotel is True:
>> countries = [
>> {'name': y, 'title': x, 'selected': y == address_country}
>> for x, y in root.get_active_countries(context) ]
>> else:
>> countries = [
>> {'name': y, 'title': x, 'selected': y == address_country}
>> for x, y in root.get_authorized_countries(context) ]
>>
>> Thanks
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list