What's the difference between running a script under command box and interpreter?
Peter J. Holzer
hjp-python at hjp.at
Mon Nov 4 16:05:21 EST 2019
On 2019-11-03 16:34:39 -0800, jfong at 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).
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20191104/20983cac/attachment.sig>
More information about the Python-list
mailing list