Created
May 10, 2017 10:09
Direct assignment to local variables different for Python 2 and 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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