0

I'm writing a spider. And in that spider I need to yield requests, with different params. It is something like,

for i in xrange(0, len(products), k):
    some_ids = ','.join([a_product['id'] for a_product in products[i: i + k]])
    for a_condition in ['c1', 'c2', 'c3']:
        yield CustomRequest(url='api:endpoint',
                            params=dict(Condition=a_condition,
                                        param1='val1',
                                        param2=some_ids,
                                       )
                           )

Is there more pythonic way to do this?

pnv
  • 2,985
  • 5
  • 29
  • 36

1 Answers1

0

Is there more pythonic way to do this?

it's kind of vague question, it depends what you're trying to accomplish, it's difficult to tell how rest of your code looks like. In general generators are great so you should use them if you can. They are definitely 'Pythonic' but your top priority should probably be having clean, efficient and working code, adhering to idioms of language is not most important thing IMO.

Community
  • 1
  • 1
Pawel Miech
  • 7,742
  • 4
  • 36
  • 57