git @ Cat's Eye Technologies Dipple / master python / pass-dict-style.py
master

Tree @master (Download .tar.gz)

pass-dict-style.py @masterraw · history · blame

# New Python programming style!
# Never return values.
# Always pass around a dict instead.

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

def foo(v):
    v['sum'] = v['a'] + v['b']
    v['rat'] = v['a'] / v['b']

def main():
    v = dict(a=10, b=1)
    foo(v)
    print(v['sum'])
    v['b'] = 0
    try:
        foo(v)
    except:
        pass
    print(v['sum'])

main()