Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # variable_tracker.py
- xxx = 'xxx'
- yyy = 'yyy'
- ddd = {xxx: 5, yyy: 0}
- def test():
- print(tr(xxx))
- print(tr(yyy))
- print(tr(yyy))
- print(tr(yyy))
- print(tr(yyy,0))
- print(tr(yyy))
- print(tr(yyy))
- print(tr(xxx))
- print(tr('zzz',99))
- print(tr(zzz))
- def tr(var, i='void'):
- if var in ddd:
- if i != 'void':
- ddd[var] = i
- else:
- ddd[var] += 1
- return ddd[var]
- else:
- exec('global '+var+'; '+var+' = "'+var+'"') # caution: exec() can corrupt if used unwisely !!!
- ddd[var] = i
- return i
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement