0

I recently found out that the following snippet:

d = {1:"one" , 2:"two"}
id1 = id(d)

del(d)

d = {1:"one" , 2:"two"}
id2 = id(d)

print(id1==id2)

If it's executed via python interpreter (e.g. using terminal) returns True and if it's run in the IDLE Shell returns False.

enter image description here

I am aware that IDLE it's (more or less) an integrated dev environment written in Python , but I would really like to know what happens behind the scenes. Thanks .

dejanualex
  • 3,872
  • 6
  • 22
  • 37
  • when i run on REPL , it returned true, which infact is correct.On which specific IDLE you got false? – Sandrin Joy Oct 03 '20 at 12:03
  • 1
    The reuse of immutable objects depends on the implementation, python version and even release, and execution mode. In interactive mode, each statement is treated like a separate file and compiled and executed by itself. In 'file' or batch mode, multiple statements are compiled and then executed together. When IDLE *simulates* interactive mode, each statement is compiled by itself in the IDLE process but then executed with an exec() call in a separate execution process running in batch mode. IDLE itself has nothing to do with how python in the second process reused objects. – Terry Jan Reedy Oct 04 '20 at 20:39
  • To summarize, the title here should be something "Python interactive vs exec() in batch mode memory use". Originally, and still with the command line -n switch, IDLE did the exec() call in its own process. But suggested title would still apply. – Terry Jan Reedy Oct 04 '20 at 20:48

0 Answers0