-1

Lets say i have a file 'file1.py' Its code is

import time
a = 10
print(id(a))
time.sleep(10)

I have another file say 'file2.py' Its code is

b = 10
print(id(b))

I run the file1.py and it created an object that is holding value 10. Now while the code in first file is sleep for 10sec i run the file2.py and now the question is will the b will also refer to the same object created in a or it will create another object for itself. However the object created in a has not been dead yet. If both the id(a) != id(b) then how do python manage to create and separate objects for different files at different locations in memory. Why python is not assigning b to also refer to the same object created in a case as both a and b are assigned same values.

  • I’m confused by the underlying assumptions here. You’re saying two different programs use different areas of memory? … Yes, that’s how it works… – deceze Aug 28 '22 at 07:48

1 Answers1

0

The execution of two different python applications is completely independent (code wise). Maybe you should read about Scopes to understand variable declaration inside of python: https://www.w3schools.com/python/python_scope.asp

terolog
  • 36
  • 2