#!/usr/bin/env python # -*- coding: utf-8 -*- """\ bug_configparser_update_order.py - configparser.update() changes order ====== ==================== usage: bug_configparser_update_order.py ====== ==================== OrderedDict does not change the order of keys upon .update(): >>> od = OrderedDict((('section1', {}), ('section2', {}))) >>> list(od.keys()) ['section1', 'section2'] >>> od.update((('section1', {}), ('section3', {}))) >>> list(od.keys()) ['section1', 'section2', 'section3'] But ConfigParser changes the order of sections upon .update(): >>> cfg = configparser.ConfigParser() >>> cfg.update((('section1', {}), ('section2', {}))) >>> cfg.sections() ['section1', 'section2'] >>> cfg.update((('section1', {}), ('section3', {}))) >>> cfg.sections() ['section2', 'section1', 'section3'] """ import sys from collections import OrderedDict try: import configparser except ImportError: import ConfigParser as configparser try: configparser.ConfigParser()['DEFAULT'] except AttributeError: print('error: use Python 3') exit(1) import doctest doctest.testmod() # (progn (forward-line 1) (snip-insert "py.t.ide" t t "py") (insert "\n")) # # :ide-menu: Emacs IDE Main Menu - Buffer @BUFFER@ # . M-x `eIDE-menu' (eIDE-menu "z") # :ide: COMPILE: Run w/o args # . (progn (save-buffer) (compile (concat "python ./" (file-name-nondirectory (buffer-file-name)) " "))) # :ide: COMPILE: Run with python3 w/o args # . (progn (save-buffer) (compile (concat "python3 ./" (file-name-nondirectory (buffer-file-name)) " "))) # # Local Variables: # mode: python # truncate-lines: t # End: