def withsymbols(func):
    """decorator, if applied to a function, allows it to use Symbols,
    creating them when needed when the function is defined. A symbol
    name must start with inprefix (usually s_)."""
    # Ideas derived from Pythologic.py  by Shai Berger
    # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303057
    try:
        code = func.func_code
    except:
        raise TypeError, "function or method argument expected"
    names = code.co_names
    locally_defined = code.co_varnames
    globally_defined = func.func_globals
    defined = set(locally_defined).union(globally_defined)
    undefined = set(names) - defined

    # Update the global scope of the function func, add definitions
    # for all undefined names starting with inprefix
    for name in undefined:
        if name.startswith(Symbol.inprefix):
            func.func_globals[name] = Symbol(name)
    return func
decorator, if applied to a function, allows it to use Symbols,
    creating them when needed when the function is defined. A symbol
    name must start with inprefix (usually s_).
recipes/Python/500273_Python_symbols_toy/recipe-500273.py