[Tutor] Python Bind DNS Zone config

Alan Gauld alan.gauld at yahoo.co.uk
Thu May 4 05:50:07 EDT 2017

On 04/05/17 04:11, Nathan D'Elboux wrote:

> when i run the above code it prompts me to enter the domain so i do,
> then the out put is a "Value error: Unexpected '{' in field name

Always, always, always post the full error message.
Do not shorten it to the summary line. We can't
see the location information so er have to guess
and that's never reliable.

> So i comment out the .format statement and i get the exact output i
> want but nothing in the {} statement

The problem could be avoided by not having the format markers
in the string. This is easily done by using traditional
formatting using % characters instead of the {} style.

print("""zone {%s} IN {
        type master;
        file "zones/";
        allow-transfer { none; };
        allow-query { test-test; };
};""" % new_domain)

I'm sure there is a way to do it using format() but
it probably involves a lot of escape characters etc.
I'd take the easy route and use printf style % markers.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list