Python variable scope is type specific? -
from functools import wraps def mywrapper(func): variable1 = {} variable2 = 0 @wraps(func) def newfunc(*args): if args in variable1: return variable1[args] else: variable1[args] = func(*args) variable2 = 1 return variable1[args] return newfunc
if run code, got error message "local variable variable2 not assigned". if change dictionary, worked fine variable1. confuses me on python variable scopes----does rely on type? using 2.7.6.
Comments
Post a Comment