Noah
Noah

Reputation: 1687

Python escape '$' character in variable name

I'm using bravado, which has created functions for me to call based on a swagger definition. The swagger definition contains query parameters prefixed with $. I.e. client.pet.get_pets($limit=10).

Problem is, I can't use $limit=10 because it throws a syntax error.

Is there a way to escape this in python?

Upvotes: 2

Views: 1264

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 602775

Python variable names and Python keyword argument names (which is what you actually need her) cannot contain $. You may be able to use the **kwargs syntax though:

client.pet.get_pets(**{"$limit": 10})

Upvotes: 5

Related Questions