0
Will the destructor execute ?
Class Test: def __init__(self): print('object initialization') def __del__(self): print('object destructor') t = Test() t1 = Test() print('EOA') OUTPUT object initialization object initialization EOA When I execute this program in my python 3.10 ide, I am getting the above output.But, when I execute this in other online compilers, I am getting the output as object initialization object initialization EOA object destructor object destructor I checked the version used by the online compiler. It's 3.8. So is this behavior depend upon version ?
2 Answers
+ 2
I never used an IDE, but I assume it leaves the environment open so you can run python commands after your script finishes, so you can see values of variables declared in your script - useful for debugging. Thus, it doesn't destroy objects.
I used to run scripts from command prompt with:
python -i script.py
for the same effect.
+ 1
Guess: online compiler will del all of the object and end programme, which is different from your self ide.