I was the first to vote to close, so I'll try to explain it.
First of all, it's hard to specify missing context. It's missing. It's the whole lack of something specified that's the problem.
The question consists of a single function, list_records
which apparantly is mainly called (but not exlusively so) using a list comprehension ( [list_records(race_type, year) for foo in bar]
). It might be doing something with a database (utils.dataracetype_to_DBcolumn
) and we don't have the foggiest what the input data looks like. Neither do we know the expected output.
We even can't say for sure this is the actual code in use. Phrases like "this kind of instance method" and "I am calling it mainly through list comprehension" make me wonder about the bigger picture. What data is OP after exactly?
Q:
I am calling it mainly through list comprehension, but I could return it simply as a list, what is the most pythonic way to do this? What would be the reasons to chose one method or the other?
A:
Depends on the context, which is missing in this question. Please take a look at the help center.
Gareth, being a heck of a lot smarter and more experienced in Python than me, managed to answer it anyway:
If you are going to need the whole list for some reason, then make a list. But if you only need one item at a time, use a generator.
Exactly, we don't know what OP wants to have and what he wants to do with it. A reviewer shouldn't have to guess. Too often we get questions which fail to specify something which in hindsight turns out to be very important, rendering the answers (partially) useless. I voted to close because that was a definite possibility with this question.
Hence the request for context. Preferably as much as possible, but there's such a thing as asking too much. Example input, output and a comment about what portion of the resulting data is actually useful to the OP would've been enough. I was either too absent-minded or in too much of a hurry to specify further, I guess. It's been an intense week, my apologies to anyone affected.