I'm working on an automated script for populating some configuration files for a server, and I'm having a problem with the nginx configuration file. It contains two types of recognized format() keywords (`$` and `{}`) and I want just to populate the ones with curly braces. The problem is that I can't escape the keywords like $proxy\_add\_x\_forwarded\_for (I should be able with `$$` but it doesn't work for some reason) and the script returns KeyErrors. Does anybody have and idea of how can I escape this?

**nginx.conf (instance\_name in this case)**

```
location /{instance_name} {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header SCRIPT_NAME /{instance_name};
    proxy_redirect off;
    proxy_pass unix:/var/run/openmooc/askbot/{instance_name}.sock;
}

```

**The replacement code:**

```
def _populate_file(self, original_file, values):

    """
    Basic abstraction layer for populating files on demand

    original_file has to be a path to the file in string format
    values is a dictionary containing the necessary key:value pairs.
    """
    f = open(original_file, 'r')
    file_content = f.read()
    f.close()
    # Create a new populated file. We use ** so we can use keyword replacement
    populated_settings = file_content.format(**values)
    # Open the file in write mode so we can rewrite it
    f = open(original_file, 'w')
    f.write(populated_settings)
    f.close()

# Call to action
template = os.path.join(INSTANCE_DIR, 'nginx.conf')
values = {'instance_name': instance_name}
self._populate_file(template, values)

```

**SOLVED**: As @Blender said, format() is taking the entire location block as a keyword to replace. The simplest solution was to put double curly braces to escape them. The solution from @FoxMaSk is also right, but it wasn't what I was looking for