Stupid question with (for sure) simple answer...
I am using configparser to read some strings from a file. When the string has the '%' symbol ($%& for example) it complains:
ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%&'"
Anybody familiar with this?
Thanks!
如果您不想替换环境变量,请使用 RawConfigParser,而不是 ConfigParser。
Write two %
:
V = ('%%', 'MHz', 'GHz')
result:
('%', 'MHz', 'GHz')
In newer Python versions, use
configParser = configparser.ConfigParser(interpolation=None)
This disables interpolation.
Note that RawConfigParser
is a legacy variant. From the python docs :
Consider using ConfigParser instead which checks types of the values to be stored internally. If you don't want interpolation, you can use ConfigParser(interpolation=None).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.