Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configparser and string with %

Tags:

python

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!

like image 765
Hüsk3rDü Avatar asked Jan 15 '13 14:01

Hüsk3rDü


People also ask

What is ConfigParser ConfigParser ()?

ConfigParser is a Python class which implements a basic configuration language for Python programs. It provides a structure similar to Microsoft Windows INI files. ConfigParser allows to write Python programs which can be customized by end users easily.

Does ConfigParser come with Python?

configparser comes from Python 3 and as such it works well with Unicode.

What is config () in Python?

A Python configuration file is a pure Python file that populates a configuration object. This configuration object is a Config instance.

How do I print a ConfigParser object?

Just use a StringIO object and the configparser's write method. It looks like the only method for "printing" the contents of a config object is ConfigParser. write which takes a file-like object. io.


2 Answers

If you don't want environment variable substitution, then use RawConfigParser, not ConfigParser.

like image 182
Ned Batchelder Avatar answered Oct 16 '22 00:10

Ned Batchelder


Write two %:

V = ('%%', 'MHz', 'GHz') 

result:

('%', 'MHz', 'GHz') 
like image 23
Artem Baranov Avatar answered Oct 16 '22 01:10

Artem Baranov