Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Interpreter and running a .py file give different outputs
#1
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.
buran wrote Jul-14-2019, 06:57 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
Memory locations are not ever guaranteed to be in the same location. It' assigned at time or operation.
Quote
#3
(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?
Quote
#4
Bump.
Quote
#5
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.
Quote
#6
(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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  error running script in python3.7.2 interpreter srm 4 421 May-23-2019, 01:09 PM
Last Post: snippsat
  Batch file not running python script in task scheduler davork 3 582 May-09-2019, 12:53 PM
Last Post: Gribouillis
  Python unittest - running multiple tests from CSV file asheru93 0 423 Jan-21-2019, 08:26 AM
Last Post: asheru93
  Problems running exe file from pyinstaller ersa21 4 624 Jan-15-2019, 06:36 PM
Last Post: snippsat
  Running another python file from code Stefanovietch 1 456 Nov-18-2018, 09:59 PM
Last Post: ichabod801
  Save outputs to Desktop cisicomania 1 515 Aug-31-2018, 10:08 AM
Last Post: Gribouillis
  Mix-in class tree file not running the self test code. arjunsingh2908 3 630 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  Help Editing/Problem with outputs stanthaman42 7 902 Jul-11-2018, 05:30 PM
Last Post: ichabod801
  how do i rewrite this code to give me 10 outputs BlackPimpernel 2 604 Mar-29-2018, 11:29 AM
Last Post: BlackPimpernel
  Running Sql query stored in CSV file purnima1 16 13,253 Oct-10-2017, 05:10 AM
Last Post: purnima1

Forum Jump:


Users browsing this thread: 1 Guest(s)