Created
July 16, 2020 18:57
-
-
Save mtholder/d5dd842bfbf78a65c50bb3732b8e3dd8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
def func(arg): | |
a_var.append(1) | |
loc_a_var = arg | |
b_var = list(arg) | |
print('func({} with id: {} and ids: {})'.format(repr(arg), id(arg), [id(i) for i in arg])) | |
print(' locals: {}'.format({k: id(v) for k, v in locals().items() if not k.startswith('__')})) | |
print(' globals: {}'.format({k: id(v) for k, v in globals().items() if not k.startswith('__')})) | |
if arg[0] > 0: | |
func([arg[0] - 1, arg[1]]) | |
a_var = [2, ('some', 'tuple')] | |
print('global arg = ({} with ids: {})'.format(repr(a_var), [id(i) for i in a_var])) | |
print(' locals: {}'.format({k: id(v) for k, v in locals().items() if not k.startswith('__')})) | |
print(' globals: {}'.format({k: id(v) for k, v in globals().items() if not k.startswith('__')})) | |
func(a_var) | |
print('global arg = ({} with ids: {})'.format(repr(a_var), [id(i) for i in a_var])) | |
print(' locals: {}'.format({k: id(v) for k, v in locals().items() if not k.startswith('__')})) | |
print(' globals: {}'.format({k: id(v) for k, v in globals().items() if not k.startswith('__')})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment