Python Forum
Interpreter and running a .py file give different outputs
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.
Reply
#2
Memory locations are not ever guaranteed to be in the same location. It' assigned at time or operation.
Reply
#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?
Reply
#4
Bump.
Reply
#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.
Reply
#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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multi set string inputs/outputs kwmcgreal 2 255 Sep-26-2020, 10:44 PM
Last Post: kwmcgreal
  How to use subprocess to get multiple data outputs in desired folder? 3SG14 1 326 Sep-19-2020, 05:46 PM
Last Post: bowlofred
  WinError 87 while running .exe file Timych 0 383 Aug-06-2020, 02:36 PM
Last Post: Timych
  Question re: running code in Editor (i.e. Atom) vs Python interpreter rok 3 449 Jun-29-2020, 09:20 PM
Last Post: bowlofred
  Multiproccessing ValueError: Pool not running when running parallel functions Gilush 1 518 Jun-06-2020, 12:49 AM
Last Post: Gilush
  Python interpreter - output to file SectionProperties 8 822 Apr-11-2020, 01:38 PM
Last Post: SectionProperties
  Outputs missing SamAnw 4 464 Feb-12-2020, 04:32 PM
Last Post: adetheheat
  problem running python file using cmd panzers 2 571 Dec-19-2019, 04:04 PM
Last Post: panzers
  error running script in python3.7.2 interpreter srm 4 1,923 May-23-2019, 01:09 PM
Last Post: snippsat
  Batch file not running python script in task scheduler davork 3 1,771 May-09-2019, 12:53 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020