1

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
  • 115,751
  • 26
  • 228
  • 437
Mike
  • 99
  • 2
  • 8

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
  • 22,927
  • 7
  • 34
  • 52
  • f-strings have the same problem as OP's code, which you just silently fixed without explanation… – deceze Aug 19 '21 at 13:31