Python: Multiline strings with inline variables

26 Views Asked by At

I'm trying to use inline variables in the multiline string to form a GraphQL query.

query = '''query {
gapc {
    search_gapc_parts(part_number: "xxx", query: "XXX" limit: 1) {
    items {
        gapc_attributes {
        name
        value
        }

        weight_g
        length_mm
        height_mm
        weight_g
    }
    }
}
}'''

Instead of xxx and XXX I want to use p_code and m_name variables like this:

query = '''query {
gapc {
    search_gapc_parts(part_number: "{}", query: "{}" limit: 1) {
    items {
        gapc_attributes {
        name
        value
        }

        weight_g
        length_mm
        height_mm
        weight_g
    }
    }
}
}'''.format(p_code, m_name)

The terminal shows this error:

Traceback (most recent call last):
  File "c:\Users\aguli\Рабочий стол\partly feature import\test.py", line 24, in <module>
    }'''.format(p_code, m_name)
ValueError: unexpected '{' in field name

I tried various methods of inline variables but the same error appeared.

0

There are 0 best solutions below