On 2019-11-04 21:05, Peter J. Holzer wrote:
On 2019-11-03 16:34:39 -0800, jf...@ms4.hinet.net wrote:
I innocently thought that when import module through "from test import
*", I am working on test's globals under REPL. I didn't noticed the
REPL has its own globals.

Well, you imported every global from test. So you are (kind of) working
on those globals, or at least the objects they are referencing.

In the real world, when you import a car from Germany, the car is now in
your country, but you are not in Germany. Even if you import all the
cars from Germany, you are still not in Germany.

It's the same way in Python.

Well, kind of. One important difference is that when you import a car
from Germany, that car is no longer in Germany. But when you import a
symbol from a Python module, that symbol still exists in that module.
You just have a second symbol in your namespace referencing the same
object (as Cameron pointed out).

The car itself isn't in Germany or your own country, it's just "somewhere". All you've imported is a (copy of a) reference to that car, under some name, and there can be other references to it in other places too, possibly under the same name, possibly under a different name.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to