Preserve case in ConfigParser?

The documentation is confusing. What they mean is this: import ConfigParser, os def get_config(): config = ConfigParser.ConfigParser() config.optionxform=str try: config.read(os.path.expanduser(‘~/.myrc’)) return config except Exception, e: log.error(e) c = get_config() print c.options(‘rules’) I.e. override optionxform, instead of calling it; overriding can be done in a subclass or in the instance. When overriding, set it to a … Read more

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

super() (without arguments) was introduced in Python 3 (along with __class__): super() -> same as super(__class__, self) so that would be the Python 2 equivalent for new-style classes: super(CurrentClass, self) for old-style classes you can always use: class Classname(OldStyleParent): def __init__(self, *args, **kwargs): OldStyleParent.__init__(self, *args, **kwargs)

Lists in ConfigParser

I am using a combination of ConfigParser and JSON: [Foo] fibs: [1,1,2,3,5,8,13] just read it with: >>> json.loads(config.get(“Foo”,”fibs”)) [1, 1, 2, 3, 5, 8, 13] You can even break lines if your list is long (thanks @peter-smit): [Bar] files_to_check = [ “/path/to/file1”, “/path/to/file2”, “/path/to/another file with space in the name” ] Of course i could … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)