Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save johnwcowan/98f5b500759a72863c1b103db9f6d0ef to your computer and use it in GitHub Desktop.

Select an option

Save johnwcowan/98f5b500759a72863c1b103db9f6d0ef to your computer and use it in GitHub Desktop.
mysterious a and b behavior
Contents of a.py:
#!/usr/bin/env python3
import b
foo = None
def main():
global foo
foo = 32
print(f'in a, foo={foo}')
b.b()
if __name__ == "__main__":
main()
Contents of b.py:
import a
def b():\
print(f'in b, a.foo={a.foo}')
Outputs:
$ python
Python 3.13.5 (main, Jun 25 2025, 18:55:22) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import a
>>> a.main()
in a, foo=32
in b, a.foo=32
>>> quit
$ ./a.py
in a, foo=32
in b, a.foo=None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment