Last active
October 19, 2015 10:36
-
-
Save Hornwitser/fdb9e6abd60ab6396ed9 to your computer and use it in GitHub Desktop.
Revisions
-
Hornwitser revised this gist
Oct 19, 2015 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,6 @@ lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py', 'w').write('\n'.join(['# Modified config', '{']+lines+['}'])) # Sample cfg.py { 'Hello': 'World', @@ -19,5 +18,4 @@ 'sample dict': {'key': 'nested dict', 'purpose': 'test'}, 'sample list': [3.14, 'mixed list', 3000], 'sample tuple': ('foo', 'bar', 123), } -
Hornwitser revised this gist
Oct 19, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,8 @@ lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py', 'w').write('\n'.join(['# Modified config', '{']+lines+['}'])) """ # Sample cfg.py { 'Hello': 'World', 'entry 1': 'This is a simple configuration file', -
Hornwitser revised this gist
Oct 19, 2015 . 2 changed files with 16 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,19 @@ # Write the changed config file back lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py', 'w').write('\n'.join(['# Modified config', '{']+lines+['}'])) # Sample cfg.py """ # Sample config file { 'Hello': 'World', 'entry 1': 'This is a simple configuration file', 'entry 2': 'loader and writer for python.', 'entry 3': 'It can read and write any object that', 'entry 4': 'can be reproduced with repr().', 'sample dict': {'key': 'nested dict', 'purpose': 'test'}, 'sample list': [3.14, 'mixed list', 3000], 'sample tuple': ('foo', 'bar', 123), } """ -
Hornwitser revised this gist
Oct 19, 2015 . 2 changed files with 17 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # Sample config file { 'Hello': 'World', 'entry 1': 'This is a simple configuration file', 'entry 2': 'loader and writer for python.', 'entry 3': 'It can read and write any object that', 'entry 4': 'can be reproduced with repr().', 'sample dict': {'key': 'nested dict', 'purpose': 'test'}, 'sample list': [3.14, 'mixed list', 3000], 'sample tuple': ('foo', 'bar', 123), } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ # Read the config file config = eval(open('cfg.py').read()) # Use it like any other dict config['Hello'] = 'Modified World' # Write the changed config file back lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py', 'w').write('\n'.join(['# Modified config', '{']+lines+['}'])) -
Hornwitser revised this gist
Oct 19, 2015 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,5 @@ config = eval(open('cfg.py').read()) # Writing the config file lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py').write('\n'.join(['# Simple config file', '{']+lines+['}'])) -
Hornwitser created this gist
Oct 19, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # Reading the config file config = eval(open('cfg.py').read()) # Writing the config file import time comment = ' '.join(['# Config written on', time.asctime()]) lines = [' {!r}: {!r},'.format(k, config[k]) for k in sorted(config)] open('cfg.py').write('\n'.join([comment, '{']+lines+['}']))