I want to do the following
"@file %(unitname).C" % {'unitname开发者_如何学运维':'Test'}
but it complains about the '.C'. How can I escape the '.' character?
You don't. You fix the format specifier.
"@file %(unitname)s.C" % {'unitname':'Test'}
Another option is,
"@file {unitname}.C".format(unitname='Test')
This may be preferable, since format()
will be the new standard in Python 3.
精彩评论