Scope confusion in Python REPL

Anssi Saari as at sci.fi
Thu Jan 13 09:35:29 EST 2022


Chris Angelico <rosuav at gmail.com> writes:

> When you import something, all you're doing is getting a local
> reference to it; "from foo import make_adder" is basically like saying
> "import foo; make_adder = foo.make_adder". The function itself is
> still the same, and it still remembers its original context.

Thanks, this clears it up.

The pattern matching examples that I was looking at when I got confused
are at
https://mathspp.com/blog/pydonts/pattern-matching-tutorial-for-pythonic-code
in case anyone is interested. Fairly neat stuff in my opinion.


More information about the Python-list mailing list