We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99a3e8e commit b2d7068Copy full SHA for b2d7068
samples/commonlib/use_chainmap.py
@@ -0,0 +1,20 @@
1
+#!/usr/bin/env python3
2
+# -*- coding: utf-8 -*-
3
+
4
+from collections import ChainMap
5
+import os, argparse
6
7
+defaults = {
8
+ 'color': 'red',
9
+ 'user': 'guest'
10
+}
11
12
+parser = argparse.ArgumentParser()
13
+parser.add_argument('-u', '--user')
14
+parser.add_argument('-c', '--color')
15
+namespace = parser.parse_args()
16
+command_line_args = { k: v for k, v in vars(namespace).items() if v }
17
18
+combined = ChainMap(command_line_args, os.environ, defaults)
19
+print('color=%s' % combined['color'])
20
+print('user=%s' % combined['user'])
0 commit comments