Skip to content

Instantly share code, notes, and snippets.

@cheelee
Created May 10, 2017 10:09
Direct assignment to local variables different for Python 2 and 3
import sys
def foo(op, val):
num = 1;
exec('num = num ' + op + ' val;');
print("INSIDE - num");
print(num);
return num;
if len(sys.argv) != 2:
op = '+';
else:
op = sys.argv[1];
bar = 6;
print("BEFORE - bar");
print(bar);
bar = foo(op, bar);
print("AFTER - bar");
print(bar);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment