configparser

Python extending with - using super() Python 3 vs Python 2

空扰寡人 提交于 2019-11-26 15:17:29
Originally I wanted to ask this question , but then I found it was already thought of before... Googling around I found this example of extending configparser . The following works with Python 3: $ python3 Python 3.2.3rc2 (default, Mar 21 2012, 06:59:51) [GCC 4.6.3] on linux2 >>> from configparser import SafeConfigParser >>> class AmritaConfigParser(SafeConfigParser): ... def __init_(self): ... super().__init__() ... >>> cfg = AmritaConfigParser() But not with Python 2: >>> class AmritaConfigParser(SafeConfigParser): ... def __init__(self): ... super(SafeConfigParser).init() ... >>> cfg =

Lists in ConfigParser

心已入冬 提交于 2019-11-26 10:07:14
问题 The typical ConfigParser generated file looks like: [Section] bar=foo [Section 2] bar2= baz Now, is there a way to index lists like, for instance: [Section 3] barList={ item1, item2 } Related question: Python’s ConfigParser unique keys per section 回答1: There is nothing stopping you from packing the list into a delimited string and then unpacking it once you get the string from the config. If you did it this way your config section would look like: [Section 3] barList=item1,item2 It's not

Python extending with - using super() Python 3 vs Python 2

扶醉桌前 提交于 2019-11-26 04:20:45
问题 Originally I wanted to ask this question, but then I found it was already thought of before... Googling around I found this example of extending configparser. The following works with Python 3: $ python3 Python 3.2.3rc2 (default, Mar 21 2012, 06:59:51) [GCC 4.6.3] on linux2 >>> from configparser import SafeConfigParser >>> class AmritaConfigParser(SafeConfigParser): ... def __init_(self): ... super().__init__() ... >>> cfg = AmritaConfigParser() But not with Python 2: >>> class