3

I have a script that is reading an ini file. When I initially wrote the script I was using a default ini. ConfigParser returned the values of the keys in a list. EG config.get('Section', 'Key') would return ['value']. I simply tacked on a slice and moved along.

However once I deployed the script and started reading ini files on customer machines ConfigParser started returning strings, not lists. So config.get('Section', 'Key') would return 'value'. Slicing that was causing no end of problems.

I have tentatively solved the issue by trying to use the string first and, if it fails, slap a slice on it. A kludge at best.

I have tried to find out why ConfigParser is returning the value as a list but none of my searches have yielded results. In fact according to the docs there is no method to do this since one of the most common questions here on SE for ConfigParser and list is how to get it to return values in a list!

My question is twofold. Why is it returning a list and how can I force it not to do so?

This is in Python 2.7.11 and the only thing that is changing is the ini file as the entire script is packaged up with py2exe for distribution.

Mushahid Khan
  • 2,816
  • 1
  • 19
  • 32
Greyed
  • 31
  • 3
  • In order to understand this would it be possible for you to include the calling code/method and an example of the config please. – PythonTester Aug 22 '16 at 19:23

0 Answers0