Python3 - How do I import a class from another file
On 12/10/19 5:44 AM, R.Wieser wrote:
>> Well, that's exactly what happens.
> So, only the reference count gets lowered. Yep, thats daft.
a = someobject
b = a
How many references for someobject? After "del a" what should be be?
It's still someobject (the same object).
Or the example Antoon provided:
b = Bar()
# b reference is deleted automatically
> ... unless you explain why it can only be done that way.
That is how a ref-counting resource management system works.
> I tend to go with logic. No logic => it most likely doesn't work that way.
Interestingly I just saw a podcast recently titled, "Why too much logic
leads to irrationality." In this case your logic is faulty because, as
you say, you lack information, which others have tried to provide.
> Choosing to go with a delayed action like you say will, as I already
> explained, create problems later on (race conditions everywhere). And as I
> do not think the designers of the language where that stupid I must
> therefore reject your claim to what you think happens.
No, that is exactly what happens. And for good reasons. Google for
reference-counting garbage collection. This is not just some brand new
Python thing. Be careful who you call stupid. Seriously. Doesn't
reflect well on you, who by your own admission is still learning the
language. Python is not C++; don't code like it is. If you need
semantics that are like RAII, then as Chris has said, you need to look
at the "with" statement and context handlers.
> But, as you mentioned, I do not know (all) the facts. Please do present
>them. Maybe there is a logic in there I do not yet see.
And that's exactly what Chris and others did. They explained the facts
and how relying on "del" to release the GPIO pin only works because you
>> Check out the 'with' statement.
> I'm sorry, but nope.