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
  error "cannot identify image file" part way through running hatflyer 0 662 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  format json outputs ! evilcode1 3 1,734 Oct-29-2023, 01:30 PM
Last Post: omemoe277
  Formatting outputs created with .join command klairel 2 616 Aug-23-2023, 08:52 AM
Last Post: perfringo
  Web project and running a .py file emont 0 636 Dec-11-2022, 11:15 PM
Last Post: emont
  I have written a program that outputs data based on GPS signal kalle 1 1,161 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  batch file for running python scipt in Windows shell MaartenRo 2 1,882 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  Why does absence of print command outputs quotes in function? Mark17 2 1,374 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,465 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  PyCharm One Interpreter for every file? muzikman 3 1,857 Sep-28-2021, 02:09 AM
Last Post: snippsat
  Combining outputs into a dataframe rybina 0 1,671 Mar-15-2021, 02:43 PM
Last Post: rybina

Forum Jump:

User Panel Messages

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