Dynamic variable name in python

Solution 1:

You can create a dictionary, set the parameters and pass this to the function by unpacking the dictionary as keyword arguments:

field_name = funct()
params = {field_name + '__lte': arg1,       # field_name should still contain string
          'some_other_field_name': arg2}

locations = Locations.objects.filter(**params)

# is the same as (assuming field_name = 'some_name'):
# Locations.objects.filter(some_name__lte=arg1, some_other_field_name=arg2)