Hi Eryk,

Thanks for the detailed explanation given. I think I got it now. :)

Regards,
JY

-----Original Message-----
From: eryk sun [mailto:[email protected]] 
Sent: Wednesday, July 12, 2017 8:13 AM
To: [email protected]
Cc: Jia Yue Kee <[email protected]>
Subject: Re: [Tutor] Python __del__ method

On Wed, Jul 12, 2017 at 12:07 AM, eryk sun <[email protected]> wrote:
> On Tue, Jul 11, 2017 at 2:47 PM, Jia Yue Kee <[email protected]> 
> wrote:
>>
>> Case 2: If I were to run the code in "Interactive Mode", the following 
>> output will be obtained:
>>
>>>>> x = Robot("Tik-Tok")
>> Tik-Tok has been created!
>>>>> y = Robot("Jenkins")
>> Jenkins has been created!
>>>>> z = x
>>>>> z
>> <__main__.Robot object at 0x02D7E910>
>>>>> x
>> <__main__.Robot object at 0x02D7E910>
>>>>> del x
>>>>> del z
>>>>> del y
>> Robot has been destroyed
>>
>> My question being why is that "Robot has been destroyed" is only 
>> printed once in Case 2 (interactive mode) while it is printed out twice in 
>> Case 1 (script mode)?
>
> The REPL (interactive mode) keeps a reference to the last non-None 
> result as builtins `_`, for convenient access to the last result. In 
> your case, it results from evaluating `x`. Thus you have a hidden 
> reference that's keeping that object alive. Enter anything except None 
> or _ to clear that reference.

Well, not just any statement. It has to evaluate to another object except None 
or the Robot object that _ currently references. For example, enter 42.
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to