Python Forum

Full Version: Interpreter and running a .py file give different outputs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have written the following code which gives different output when saved as a .py file and run and on the Python interpreter.

a=100000
b=a
c=100000
print (id(a),id(b),id(c))
Output when saving as .py file and running through command prompt:
2122603390032 2122603390032 2122603390032

All memory addresses are same.


Output via interpreter:
2351093736464 2351093736464 2351093736304

Last memory address is different.


Why is this happening? I am on Python 3.7.4.
What are the differences when running on the interpreter and when running a .py file.
Memory locations are not ever guaranteed to be in the same location. It' assigned at time or operation.
(Jul-14-2019, 10:14 AM)Larz60+ Wrote: [ -> ]Memory locations are not ever guaranteed to be in the same location. It' assigned at time or operation.

Yes, I am aware of that.

But every time I run the .py file, the memory locations are the same, while every time I run the same code via the interpreter the memory locations are different.

So is it that the interpreter runs programs slightly differently as compared to running a .py file directly?
Bump.
Quote:What are the differences when running on the interpreter and when running a .py file.
I already answered a similar question. See here to see if it explains this behaviour.
(Jul-21-2019, 07:25 AM)Gribouillis Wrote: [ -> ]
Quote:What are the differences when running on the interpreter and when running a .py file.
I already answered a similar question. See here to see if it explains this behaviour.

Thank you! Exactly the answer I was looking for.