Skip to content

Instantly share code, notes, and snippets.

@claudijd
Created July 3, 2019 18:20
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 claudijd/9dfe804e99c0f090136a86f9ac764ac7 to your computer and use it in GitHub Desktop.
Save claudijd/9dfe804e99c0f090136a86f9ac764ac7 to your computer and use it in GitHub Desktop.
demoing global override and comms
thing = "foo"
class Baz():
def override_thing(self):
global thing
thing = 1
def update_thing(self):
global thing
thing += 1
def read_thing(self):
global thing
return thing
baz = Baz()
baz2 = Baz()
print thing
baz.override_thing()
print thing
baz.update_thing()
print thing
print baz.read_thing()
print baz2.read_thing()
@claudijd
Copy link
Author

claudijd commented Jul 3, 2019

$ python ~/Desktop/shark.py
foo
1
2
2
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment