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 <[email protected]> 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 - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor