Skip to content

Instantly share code, notes, and snippets.

@Hornwitser
Last active October 19, 2015 10:36
Show Gist options
  • Save Hornwitser/fdb9e6abd60ab6396ed9 to your computer and use it in GitHub Desktop.
Save Hornwitser/fdb9e6abd60ab6396ed9 to your computer and use it in GitHub Desktop.

Revisions

  1. Hornwitser revised this gist Oct 19, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions config.py
    Original 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),
    }
    """
    }
  2. Hornwitser revised this gist Oct 19, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions config.py
    Original 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
    """
    # Sample config file
    # Sample cfg.py
    {
    'Hello': 'World',
    'entry 1': 'This is a simple configuration file',
  3. Hornwitser revised this gist Oct 19, 2015. 2 changed files with 16 additions and 12 deletions.
    11 changes: 0 additions & 11 deletions cfg.py
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@
    # 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),
    }
    17 changes: 16 additions & 1 deletion config.py
    Original 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+['}']))
    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),
    }
    """
  4. Hornwitser revised this gist Oct 19, 2015. 2 changed files with 17 additions and 3 deletions.
    11 changes: 11 additions & 0 deletions cfg.py
    Original 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),
    }
    9 changes: 6 additions & 3 deletions config.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # Reading the config file
    # Read the config file
    config = eval(open('cfg.py').read())

    # Writing the config file
    # 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').write('\n'.join(['# Simple config file', '{']+lines+['}']))
    open('cfg.py', 'w').write('\n'.join(['# Modified config', '{']+lines+['}']))
  5. Hornwitser revised this gist Oct 19, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions config.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,5 @@
    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+['}']))
    open('cfg.py').write('\n'.join(['# Simple config file', '{']+lines+['}']))
  6. Hornwitser created this gist Oct 19, 2015.
    8 changes: 8 additions & 0 deletions config.py
    Original 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+['}']))