I'm trying to substitute a variable called id in the below string
query = '''SELECT ?item ?itemLabel WHERE {?item wdt:P279* wd:Q7930989. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}'''
I'd like to do something like
id = "wd:Q7930989"
query = f'''SELECT ?item ?itemLabel WHERE {?item wdt:P279* {id}. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}'''
When I try to run the above code, I run into errors like KeyError: '?item wdt’
I think this might be due to the brackets already within the string. I’d ideally like a way to escape these brackets so that I can insert {id} into the string.
Any ideas?