0

I ran the following code below in Python:

configuration_str= """
    configuration={
                "query": {
                "query": "CALL `{0}.{1}.{2}`(); ",
                "useLegacySql": False,
            }
            },

""".format("server_name", "dataset_name", "sp_name")

I got the error below:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
KeyError: '\n                    "query"'

What is the issue and how to fix it?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Mike
  • 69
  • 1
  • 7

1 Answers1

0

how about using f string

server_name = 'A'
dataset_name = 'B'
sp_name ='C'

configuration_str = f"""configuration={{
                "query": {{
                "query": "CALL '{server_name}.{dataset_name}.{sp_name}'(); ",
                "useLegacySql": False,
            }}
            }}"""

print(configuration_str)

output

configuration={
                "query": {
                "query": "CALL 'A.B.C'(); ",
                "useLegacySql": False,
            }
            }
balderman
  • 21,028
  • 6
  • 30
  • 43