Skip to content

Instantly share code, notes, and snippets.

@icarrr
Created November 21, 2019 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icarrr/c36db63a63206c5d342d3516169f3ded to your computer and use it in GitHub Desktop.
Save icarrr/c36db63a63206c5d342d3516169f3ded to your computer and use it in GitHub Desktop.
Access a function variable outside the function without using “global”
def hi():
# other code...
hi.bye = 42 # Create function attribute.
sigh = 10
hi()
print(hi.bye) # -> 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment