On 2018-02-17 11:23, fhsxfhsx wrote:
> [
>   {
>     'id': goods.id,
>     'name': goods.name,
>     'category': gc.name,
>     'category_type': gc.type,
>   }
>   for goods_id in goods_id_list
>   for goods is Goods.get_by_id(goods_id)
>   for gc is GoodsCategory.get_by_id(goods.category_id)
> ]

in the short term, it seems for...in [...] is good enough:

> [
>     {
>         'id': goods.id,
>         'name': goods.name,
>         'category': gc.name,
>         'category_type': gc.type,
>     }
>     for goods_id in goods_id_list
>     for goods in [Goods.get_by_id(goods_id)]
>     for gc in [GoodsCategory.get_by_id(goods.category_id)]
> ]

I personally would like to see with...as... syntax allowed in list
comprehensions, despite `with` being limited to context managers to date.

> [
>     {
>         'id': goods.id,
>         'name': goods.name,
>         'category': gc.name,
>         'category_type': gc.type,
>     }
>     for goods_id in goods_id_list
>     with Goods.get_by_id(goods_id) as goods
>     with GoodsCategory.get_by_id(goods.category_id) as gc
> ]

..,or maybe `let` reads easier?

> [
>     {
>         'id': goods.id,
>         'name': goods.name,
>         'category': gc.name,
>         'category_type': gc.type,
>     }
>     for goods_id in goods_id_list
>     let goods = Goods.get_by_id(goods_id)
>     let gc = GoodsCategory.get_by_id(goods.category_id)
> ]




_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to