reading special characters text from .ini file in python
Looks like the %
character is the problem here. It has special meaning if you are using ConfigParser
. If you are not using interpolation, then use just RawConfigParser
instead, otherwise you must escape the %
by doubling it.
When I try the example file with ConfigParser
it will blow with the following exception:
InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%19u^l\\&G"'
If I replace ConfigParser
with RawConfigParser
everything is fine.
The error you posted has nothing to do with it. We can't even tell if it is a python exception or a shell error message. Please update your question with the full error message. You may also want to check the sh
module, a higher level wrapper around subprocess
.
Adding up on Paulo Scardine's comment.
if you have special characters that need to be handled, you can set the ConfigParser
's interpolation
argument to None
and you won't have the error anymore. ConfigParser
has interpolation
set to BasicInterpolation()
by default.
You can read more about this here: https://docs.python.org/3.6/library/configparser.html#interpolation-of-values
Further, as per the docs RawConfigParser
is a Legacy variant of the ConfigParser with interpolation disabled by default and unsafe add_section and set methods.
Here's a snippet from there:
Example:
[Paths]
home_dir: /Users
my_dir: %(home_dir)s/lumberjack
my_pictures: %(my_dir)s/Pictures
In the example above, ConfigParser with interpolation set to BasicInterpolation() would resolve %(home_dir)s
to the value of home_dir
(/Users in this case). %(my_dir)s
in effect would resolve to /Users/lumberjack
. [....]
With interpolation set to None
, the parser would simply return %(my_dir)s/Pictures
as the value of my_pictures
and %(home_dir)s/lumberjack
as the value of my_dir
.