[Tutor] improvement of if - else code
vince spicer
vinces1979 at gmail.com
Thu Jun 4 19:34:34 CEST 2009
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090604/9eb9ed62/attachment.htm>
More information about the Tutor
mailing list