osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python3 - How do I import a class from another file


On 10/12/19 16:56, Chris Angelico wrote:
> On Wed, Dec 11, 2019 at 2:36 AM Antoon Pardon <antoon.pardon at vub.be> wrote:
>> On 10/12/19 16:10, Chris Angelico wrote:
>>> On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon <antoon.pardon at vub.be> wrote:
>>>> What would you want to happen in the following case:
>>>>
>>>>    foo1 = Bar()
>>>>    foo2 = foo1
>>>>    del foo1
>>>>
>>>> Should the object be cleaned up now or not?
>>>>
>>> TBH both are plausible,
>> I find that strange because if you cleanup the object in that scenario
>> it should also
>> be cleaned up in the following.
>>
>>     def newbar():
>>         foo = Bar
>>         return foo
>>
>>     bar = newbar()
>>
>> foo goes out of scope, so that is equivallent to a del foo. But I wouldn't
>> want the object cleaned up because of that.
>>
> Going out of scope isn't the same as explicit destruction.

In the context of this discussion it is. We are talking about about
automatic cleanup
and whether it should happen immediatly after a name is no longer
available. or wait
until the object is garbage collected. The fact that I used a del for
illustrating the
possible problems is just a detail.

That other languages may have different semantics with the del statement
is irrelevant.

-- 
Antoon Pardon