0

I am trying to use a default query and then append some conditions. I would like to know how can i concatenate a string while unpacking args.

filters = []
if industry:
    filters.append('industry_id')
    filters.append('role_id')
    ...

As far as I can see this doesn't work (invalid syntax).

print "SELECT city, " + *filters + " FROM histogram"

1 Answer 1

1

Use join to do what you need:

print "SELECT city, " + ', '.join(filters) + " FROM histogram"

which prints:

SELECT city, industry_id, role_id FROM histogram
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.