开发者

How to escape character '.' in python string replacement via the operator %

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜