Trying to format list so i can execute it in a query but getting a 'list' object has no attribute 'map' and sure why? Using python 2.6 The list has string of names.
params = ",".join(flagged_job_names.map(lambda x: "?"))
cursor.execute(sql.format(params), flagged_job_names)
map
is a function, not a method of a list.
params = ",".join(map(lambda x: "?", flagged_job_names))
BTW, you can use list comprehension or generator expression instead of map
:
params = ",".join("?" for x in flagged_job_names)
But for this specific case, following are also possible:
params = ",".join(["?"] * len(flagged_job_names))
params = ",".join("?" * len(flagged_job_names))
The last one is possible, because the string (?
) is one-character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With