Re: Python3 - How do I import a class from another file

2019-12-16 Thread DL Neil via Python-list
Wow, I turned my back to attend to $job and this conversation has 'exploded' (>80 msgs)! TLDR; With apologies, I started to reply to your reply, but then added 'bits' as I read the conversation thereafter. The result (below) is a messy hodge-podge, for which I can only apologise (as I don't ha

Re: Python3 - How do I import a class from another file

2019-12-15 Thread Chris Angelico
On Sun, Dec 15, 2019 at 10:01 PM wrote: > > On Thu, 12 Dec 2019 11:33:25 + > Rhodri James wrote: > > > On 11/12/2019 21:32, mus...@posteo.org wrote: > > > Plain and simple: When the refcount reaches zero. > > > You are assuming that "when" implies "immediately on the occurence." > > I'm not i

Re: Python3 - How do I import a class from another file

2019-12-15 Thread musbur
On Thu, 12 Dec 2019 11:33:25 + Rhodri James wrote: > On 11/12/2019 21:32, mus...@posteo.org wrote: > > Plain and simple: When the refcount reaches zero. > You are assuming that "when" implies "immediately on the occurence." I'm not implying that. It's the dictionary definition of the word

Re: Python3 - How do I import a class from another file

2019-12-13 Thread Greg Ewing
On 14/12/19 5:13 pm, boB Stepp wrote: is it true that CPython itself is free to implement these behaviors differently in its own future versions? Yes. That's why it's not a good idea to rely on them even if you only intend to run your code on CPython. -- Greg -- https://mail.python.org/mailman

Re: Python3 - How do I import a class from another file

2019-12-13 Thread boB Stepp
On Wed, Dec 11, 2019 at 6:51 PM Greg Ewing wrote: > > On 12/12/19 3:50 am, R.Wieser wrote: > > I was rather clear about what my used version of Python was-and-is. I have > > no idea why that was ignored. :-( > > I think we've all been talking at cross purposes for a while. > > What I meant to say

Re: Python3 - How do I import a class from another file

2019-12-13 Thread Antoon Pardon
On 11/12/19 14:42, R.Wieser wrote: > Michael, > >> It's a two-way street. It's hard to teach someone that won't be taught. > Whacking a student over the head because he doesn't understand has never > helped the student*. You were not whacked for not understanding. You were wacked for pretending

Re: Python3 - How do I import a class from another file

2019-12-12 Thread Musbur
Hi Chris, The most important distinction, which that note is emphasizing, is that the "del" statement removes just one reference, and if there are other references, then __del__ will not be called. No argument there, that's how reference counting works, and it's clear from the docs. What is n

Re: Python3 - How do I import a class from another file

2019-12-12 Thread Rhodri James
On 11/12/2019 21:32, mus...@posteo.org wrote: On Tue, 10 Dec 2019 14:56:10 -0500 Dennis Lee Bieber wrote: It is called when the language IMPLEMENTATION decides to call it. That time is not specified in the language description/reference manual. Yes it is: "Note: del x doesn’t directl

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Chris Angelico
On Thu, Dec 12, 2019 at 1:33 PM Daniel Haude wrote: > > Am 10.12.2019 22:29 schrieb Chris Angelico: > > > And once again, you are maintaining your assumptions despite being > > very clearly shown that they are wrong. "del instance" does not > > directly call __del__ any more than "instance = 1" do

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 12/12/19 2:17 pm, Python wrote: I was very impressed back in the day when the with statement and context manager protocol appeared in Python. I've always wondered from what language(s) it was borrowed from It was partly inspired by the RAII pattern often used in C++, but as far as I know, al

Re: Python3 - How do I import a class from another file

2019-12-11 Thread musbur
On Tue, 10 Dec 2019 22:08:48 +0100 "R.Wieser" wrote: > And although you have been fighting me over when the __del__ method is > called, it /is/ called directly as a result of an "del instance" and > the refcount goes zero. There is /no/ delay.(with the only > exception is when a circular ref

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Daniel Haude
Am 10.12.2019 22:29 schrieb Chris Angelico: And once again, you are maintaining your assumptions despite being very clearly shown that they are wrong. "del instance" does not directly call __del__ any more than "instance = 1" does. You HAVE been shown. Much of the confusion in this thread come

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Python
Greg Ewing wrote: ... You deal with it by not relying on __del__ for anything that needs to be done promptly. There are always alternatives: e.g. file objects have a close() method, and the "with" statement was invented to make it easy to do these kinds of things properly. By the way, I was ver

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 12/12/19 3:50 am, R.Wieser wrote: I was rather clear about what my used version of Python was-and-is. I have no idea why that was ignored. :-( I think we've all been talking at cross purposes for a while. What I meant to say originally was that you were relying on an implementation detail

Re: Python3 - How do I import a class from another file

2019-12-11 Thread musbur
On Tue, 10 Dec 2019 14:56:10 -0500 Dennis Lee Bieber wrote: > > It is called when the language IMPLEMENTATION decides to call > it. That time is not specified in the language description/reference > manual. Yes it is: "Note: del x doesn’t directly call x.__del__() — the former decrements

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Roel Schroeven
R.Wieser schreef op 11/12/2019 om 11:43:> MRAB, > >> From the help: > ... >> Do not depend on immediate finalization of objects when they become >> unreachable (so you should always close files explicitly). > > Do you notice there is not a single word about (the delayed action of) the > __del__

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Musbur
Am 11.12.2019 11:22 schrieb R.Wieser: I think I will just go out on a limb and just assume that the __del__ method /will/ be called as part of a "del instance" request causing the reference count to reach zero (directly or indirectly), before the next command is executed [...]. That's what

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Musbur
Am 11.12.2019 11:01 schrieb Greg Ewing: On 11/12/19 7:47 am, R.Wieser wrote: what happens when the reference becomes zero: is the __del__ method called directly (as I find logical), or is it only called when the garbage collector actually removes the instance from memory (which Chris thinks w

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Chris, > Yes, we know exactly how that's solved, Nice. > but you specifically said you weren't interested in learning. Try taking a few courses of "understanding what you read". That is /not/ what I said. Though it goes in par with your amadant "you're wrong" chanting, even if there is at l

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Arjun pazhanikumar
You could write the name of the class variable you want to import for example class manager On December 10, 2019, at 2:46 AM, Dennis Lee Bieber wrote: On Mon, 9 Dec 2019 20:21:39 +0100, "R.Wieser" declaimed the following: > >And than when the instance is deleted the binding to the class is

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Bev, > You acknowledge that you are new to Python, yet you claimed > to know better than Python experts. You claim you want an answer > and yet you purposefully ignored their response because it didn't match > what you wanted to hear. No, I didn't. I just pointed out that their position simply w

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Chris Angelico
On Thu, Dec 12, 2019 at 1:56 AM R.Wieser wrote: > A question though: I have brought up that a delayed calling of the __del__ > method could/would most likely cause race problems. Do you have any idea > how thats solved in environents like Jython ? Yes, we know exactly how that's solved, but you

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Greg, > In CPython, these are the same thing. As soon as the reference > count becomes zero, the __del__ method is called That is what I assumed (the logical thing to do). > *and* the object is removed from memory. Which sounds reasonable too, especially in regard to the instances variables ne

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Rhodri James
On 11/12/2019 14:17, Musbur wrote: Am 10.12.2019 22:33 schrieb Paul Moore: You do understand that the reference counting garbage collector is an implementation detail of the CPython implementation *only*, don't you? I don't think that's true. Here's a sentonce from near the top of the "gc" m

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Musbur
Am 10.12.2019 22:33 schrieb Paul Moore: You do understand that the reference counting garbage collector is an implementation detail of the CPython implementation *only*, don't you? I don't think that's true. Here's a sentonce from near the top of the "gc" module documentation of Python 3: ht

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Antoon, > There is a difference between not understanding why things are as > you are told, and assuming because you don't understand, what you > are told is wrong. The other side is you guys, expecting from me that, even though I appearantly do not understand it, just take whatever has being sa

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Michael, > It's a two-way street. It's hard to teach someone that won't be taught. Whacking a student over the head because he doesn't understand has never helped the student*. So, stop whacking and start /teaching/. Like thinking of examples that could show the student where he goes wrong

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Michael, > You said it by implication. > > quote: "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." I suggest you try reading that again, and imagine it being two centences, the first ending after "stupid" and

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Bev In TX
> On Dec 11, 2019, at 6:09 AM, R.Wieser wrote: > > Paul, > >> You do understand that the reference counting garbage collector is an >> implementation detail of the CPython implementation *only*, don't you? > > No, I don't. But do tell how that matters to me. > >> there can be an indefinite

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
MRAB, > You don't "del" an instance, you "del" a reference, which might be in the > form of a name in a namespace. Remember me, the newbie to the language ? Did you understand what I tried to to say ? Good. Thats al that matters. > When the instance is collected, whenever that happens to be

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Paul, > You do understand that the reference counting garbage collector is an > implementation detail of the CPython implementation *only*, don't you? No, I don't. But do tell how that matters to me. > there can be an indefinite delay between the last reference to > a value being lost and the

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
MRAB, > From the help: ... > Do not depend on immediate finalization of objects when they become > unreachable (so you should always close files explicitly). Do you notice there is not a single word about (the delayed action of) the __del__ method in there ? Why than do you think its talking a

Re: Python3 - How do I import a class from another file

2019-12-11 Thread R.Wieser
Dennis, This is the first time I've seen you post FUD. :-(( > It is called when the language IMPLEMENTATION decides to call it. > That time is not specified in the language description/reference manual. I'm rather sure it neither specifies that for any of the other commands. Does that mean that

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 11/12/19 7:47 am, R.Wieser wrote: what happens when the reference becomes zero: is the __del__ method called directly (as I find logical), or is it only called when the garbage collector actually removes the instance from memory (which Chris thinks what happens) ? In CPython, these are the s

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Antoon Pardon
On 10/12/19 22:24, R.Wieser wrote: > Roel, > >> Rudy, unless/until you know the language inside out, you'd better listen >> to Chris and other people here who spend a lot of time and effort in >> helping people like you. > I tried. But what he said made no sense to me, and no matter how hard I

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Python
Michael Torrie wrote: On 12/10/19 2:08 PM, R.Wieser wrote: You might know a thing or two about Python, but you (and a number of others here) positivily stink as teachers, incapable or even unwilling to place themselves in the shoes of a newbie. As it happens, I've heard Chris speak about teach

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
On 12/10/19 2:08 PM, R.Wieser wrote: > You might know a thing or two about Python, but you (and a number of others > here) positivily stink as teachers, incapable or even unwilling to place > themselves in the shoes of a newbie. As it happens, I've heard Chris speak about teaching Python to studen

Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB
On 2019-12-10 21:08, R.Wieser wrote: Chris, Once again, you make positive assertions about things you don't understand. And you have refused to bring any kind of help (explanation!) forward that could have shown me the erring of my ways, as well as refusing to adress my (attempting to explain

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
On 12/10/19 11:47 AM, R.Wieser wrote: > Who did I call stupid ?I mentioned that the language doing it as Chris > thinks it happens would be stupid, and I gave a reason for that (race > conditions everywhere). But odd: Neither him nor you nor anyone else who > complains about me thinking for

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Paul Moore
On Tue, 10 Dec 2019 at 21:12, R.Wieser wrote: > And although you have been fighting me over when the __del__ method is > called, it /is/ called directly as a result of an "del instance" and the > refcount goes zero. There is /no/ delay.(with the only exception is > when a circular reference e

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 8:26 AM R.Wieser wrote: > > Roel, > > > Rudy, unless/until you know the language inside out, you'd better listen > > to Chris and other people here who spend a lot of time and effort in > > helping people like you. > > I tried. But what he said made no sense to me, and no

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Roel, > Rudy, unless/until you know the language inside out, you'd better listen > to Chris and other people here who spend a lot of time and effort in > helping people like you. I tried. But what he said made no sense to me, and no matter how hard I tried I could not get Chris (or others fo

Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris, > Once again, you make positive assertions about things you > don't understand. And you have refused to bring any kind of help (explanation!) forward that could have shown me the erring of my ways, as well as refusing to adress my (attempting to explain) examples. You might know a thing o

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Dennis, > In common Python, small integers are cached internally for reuse That is what I imagined could possibly be happening, reading the specific "the integer 5" formulation in the question ("reading between the lines" and all that). And thanks for that explanation, underbuild an all. :-)

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James
On 10/12/2019 19:25, R.Wieser wrote: And to repeat, you have*no* guarantee*at all* in the language spec that this will happen. There is also absolutily no guarantee in those specs that my 'puter will not suddenly transform into a bonzai tree. Should I now expect it to happen ? That's an im

Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB
On 2019-12-10 19:25, R.Wieser wrote: Rhodri, the object that is the integer 5 *isn't* deleted That was not the question. And you're now referring to the object as well as the integer, which makes it confusing. You also have not explained what happens instead. In short, your above statement

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Rhodri, > the object that is the integer 5 *isn't* deleted That was not the question. And you're now referring to the object as well as the integer, which makes it confusing. You also have not explained what happens instead. In short, your above statement has ZERO value to me. > On the cont

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Roel Schroeven
R.Wieser schreef op 10/12/2019 om 13:44: Also, when you scorn something without knowing your facts, you tend to make yourself look like a fool :) I tend to go with logic. No logic => it most likely doesn't work that way. Choosing to go with a delayed action like you say will, as I already e

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James
On 10/12/2019 19:00, R.Wieser wrote: MRAB, You merely disabled the mark-and-sweep collector. Nope. Go check the docs on "gc" Yep. Go and check the docs on "gc" *carefully* *plonk* -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 6:06 AM R.Wieser wrote: > > MRAB, > > > You merely disabled the mark-and-sweep collector. > > Nope. Go check the docs on "gc" > https://docs.python.org/3/library/gc.html """ This module provides an interface to the optional garbage collector. ... Since the collector sup

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
MRAB, > You merely disabled the mark-and-sweep collector. Nope. Go check the docs on "gc" Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 5:51 AM R.Wieser wrote: > > Michael, > > >> So, only the reference count gets lowered. Yep, thats daft. > > > > Why? Consider: > > You missed the point. > > It was-and-is not about decrementing a reference but still having it above > zero, but what happens when the refere

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Michael, >> So, only the reference count gets lowered. Yep, thats daft. > > Why? Consider: You missed the point. It was-and-is not about decrementing a reference but still having it above zero, but what happens when the reference becomes zero: is the __del__ method called directly (as I find

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James
On 10/12/2019 17:18, R.Wieser wrote: Chris, Okay. What should happen when you do this? x = 5 del x Should the integer 5 be deleted? Yep. What do you think happens instead ? I've not seen you explain or support anything in that regard, not even now. As it happens, the object that is the

Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB
On 2019-12-10 17:18, R.Wieser wrote: Chris, Okay. What should happen when you do this? x = 5 del x Should the integer 5 be deleted? Yep. What do you think happens instead ? I've not seen you explain or support anything in that regard, not even now. There is a bit of a problem with the a

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Antoon, > Well yes that is why it is stupid to rely on the garbage collector to do > those things for you. That is why Greg Ewing already stated: > >> If your object has a method for explicitly making it release its >> resources, it would be better to use that rather than rely on >> the garbage co

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris, > Okay. What should happen when you do this? > > x = 5 > del x > > Should the integer 5 be deleted? Yep. What do you think happens instead ? I've not seen you explain or support anything in that regard, not even now. There is a bit of a problem with the above though: It has got zero t

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Python, > which contradicts your previous statement. I don't think so. > "with" is "more stuff" it is the right way to deal with disposable > ressource in the first place. Than you have missed the point altogether. It isn't about what you think is the perfect way to deal with something, but

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
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. Why? Consider: 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

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 16:56, Chris Angelico wrote: > On Wed, Dec 11, 2019 at 2:36 AM Antoon Pardon wrote: >> On 10/12/19 16:10, Chris Angelico wrote: >>> On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon wrote: What would you want to happen in the following case: foo1 = Bar() foo2 = f

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 2:36 AM Antoon Pardon wrote: > > On 10/12/19 16:10, Chris Angelico wrote: > > On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon wrote: > >> What would you want to happen in the following case: > >> > >>foo1 = Bar() > >>foo2 = foo1 > >>del foo1 > >> > >> Should the

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 16:10, Chris Angelico wrote: > On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon 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

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon 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, and to a Python programmer it's immediately obvious that "foo1.c

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 13:44, R.Wieser wrote: > Chris, > >> Well, that's exactly what happens. > So, only the reference count gets lowered. Yep, thats daft. > > ... unless you explain why it can only be done that way. > >> Also, when you scorn something without knowing your facts, >> you tend to make yoursel

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Python
R.Wieser wrote: Chris, ... 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. We may, but then you wrote: Check out the 'with' statement. I'm sorry, but nope. Rule one: When debugging do *not* throw more stu

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Tue, Dec 10, 2019 at 11:46 PM R.Wieser wrote: > > Chris, > > > Well, that's exactly what happens. > > So, only the reference count gets lowered. Yep, thats daft. > > ... unless you explain why it can only be done that way. Okay. What should happen when you do this? x = 5 del x Should the in

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris, > Well, that's exactly what happens. So, only the reference count gets lowered. Yep, thats daft. ... unless you explain why it can only be done that way. > Also, when you scorn something without knowing your facts, > you tend to make yourself look like a fool :) I tend to go with logic

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Tue, Dec 10, 2019 at 9:51 PM R.Wieser wrote: > > Greg, > > > In that case, it was only working by accident. > > I don't think so. > > Or you must be thinking that the __del__ method of an instance is only > called by the garbage collector - which would be rather daft (just think of > a file tha

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Greg, > In that case, it was only working by accident. I don't think so. Or you must be thinking that the __del__ method of an instance is only called by the garbage collector - which would be rather daft (just think of a file thats created when initialising an instance, but not closes until t

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Greg Ewing
On 10/12/19 9:45 pm, R.Wieser wrote: In my case deleting the instance was needed to release its hold on something that was taken when the instance was initialised (in my case a GPIO pin on a Raspberry Pi). I did not even think of garbage collection. In that case, it was only working by accid

Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
DL, > I went through this cycle of thinking, first using if __name__... to > 'hide' testing, then adding test functions within the module, and now keep > test code quite separate from 'the real thing'. :-) The normal newbie progression, off of which I'm in phase #1. Having a working program

Re: Python3 - How do I import a class from another file

2019-12-09 Thread DL Neil via Python-list
It might be becoming 'long', but this discussion contains much of profit to many people! Us 'silver surfers' do need to periodically question those beliefs we hold as 'tenets' of ComSc. Amongst them is RAM (or "core"!) conservation. It remains a virtue somewhat, but at the same time, storage

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
Dennis, > "del instance" only deletes the NAME. [snip] Yep, I already assumed that that would happen. Just wanted to keep it simple. > "instance" xyz does not shadow "class" xyz... instead, the name "xyz" > only exists in the binding to the instance. That is what I tried to say: the name-bind

Re: Python3 - How do I import a class from another file

2019-12-09 Thread Python
Le 09/12/2019 à 09:15, R.Wieser a écrit : ... You'll find that *any* form of import executes all the top-level code. Thats certainly something I did not expect. How could it be otherwise? Consider a module defining two classes: Parent and Child, Child inheriting from Parent. if you do "from

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
Greg, > There's nothing stopping you from subsequently rebinding that name to some > other object, or deleting it altogether. Which is something I did not expect. But running into is what makes doing something new interesting. :-) And I just realized something else: I just assumed that the "d

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
Python, > Child *depends* on Parent. I'm sorry, but without any kind of underbuilding statements like that are of no value to me I'm afraid. Also: if I can just copy-and-paste the class into the file which origionally included it and have the whole program run without a problem than that depe

Re: Python3 - How do I import a class from another file

2019-12-09 Thread Terry Reedy
On 12/9/2019 2:36 AM, R.Wieser wrote: Terry, Standard for in-file test is [snip] Any reason to put the testcode in a procedure instead of just have it directly follow the "if __name__ == '__main__' " test ? One can, for instance, interactively do >>> import mod >>> mod.test() and explore t

Re: Python3 - How do I import a class from another file

2019-12-09 Thread Greg Ewing
On 9/12/19 9:15 pm, R.Wieser wrote: To be honest, I was not aware/did not assume that I could delete a class definition that way (I even find it a bit weird, but as I'm a newbie in regard to Python that does not say much). Python is very dynamic. The class statement is actually an executable st

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
Greg, >>> Are you sure there's a difference between classes and functions here? >> >> Yes, quite sure. > > And we're even more sure that there isn't. :-) As it turned out "we're" are right, and I was thrown off by the error message. :-p The problem is that I had no idea why I got that (rather e

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
DL, > Some of this you will know. (Hopefully) some will be 'new': Some of it is known to me, and indeed I do hope that there will be new stuff in there too. Its why I took up Python. :-) Thanks for the explanation (including the aliassing I wasn't aware of) and the links. Regards, Rudy Wiese

Re: Python3 - How do I import a class from another file

2019-12-09 Thread R.Wieser
Terry, > Not really. The resulting global objects do not normally take enough > space to worry about on normal modern desktops. For some reason I still aim to keep my (running) programs as small as possible - even though the ammount of memory has grown more than a thousandfold since I started

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Greg Ewing
On 9/12/19 6:28 am, R.Wieser wrote: Are you sure there's a difference between classes and functions here? Yes, quite sure. And we're even more sure that there isn't. :-) Try it with a test module containing a class definition, a function definition and some top-level code that does somethin

Re: Python3 - How do I import a class from another file

2019-12-08 Thread DL Neil via Python-list
On 9/12/19 7:29 AM, R.Wieser wrote: ... Note that in all cases when you import a module (either by import the_file or from the_file importe whatever) you actually import ALL of it So much for my assumption only the class itself would be loaded - and a wrench into my idea to have a number of cl

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Terry Reedy
On 12/8/2019 1:29 PM, R.Wieser wrote: from the_file import ClassName from somemod import name has the same effect as import somemod name = somemod.name del somemod which is to import a particular 'name' linked to a particular python object into the namespace where the import is executed.

Re: Python3 - How do I import a class from another file

2019-12-08 Thread R.Wieser
Dennis, > Common practice is that the class is capitalized. Instances >are lowercase. Thanks. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list

Re: Python3 - How do I import a class from another file

2019-12-08 Thread R.Wieser
Peter, >> "from file import function" works, but fails when I try to do the same >> with a class. > > Are you sure? It should behave the same for any name in the module. I am. At least, that is what the error said: "cannot import 'classname' from 'filename' " But as it turns out the problem is

Re: Python3 - How do I import a class from another file

2019-12-08 Thread R.Wieser
Python, > from the_file import ClassName > > should work. I guess that your class name is not "class" right? You guessed that right. :-) Not a good idea to pick confusing names like that, especially when you do something the first time. > Note that in all cases when you import a module (either

Re: Python3 - How do I import a class from another file

2019-12-08 Thread R.Wieser
Chris, > Are you sure there's a difference between classes and functions here? Yes, quite sure. If not my attempt to load a class he same way as a function would have worked. Which it doesn't. > Try "from file import function" and see if it runs commands at > the root of the file. What funct

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Peter Otten
R.Wieser wrote: > Hello all, > > Using Python3 I would like to import a specific class from another file > (in the same folder), and have trouble doing so. > > "from file import function" works, but fails when I try to do the same > with a class. Are you sure? It should behave the same for any

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Python
R.Wieser wrote: Hello all, Using Python3 I would like to import a specific class from another file (in the same folder), and have trouble doing so. "from file import function" works, but fails when I try to do the same with a class. "import file x = file.class" works, but also executes comman

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Chris Angelico
On Mon, Dec 9, 2019 at 3:31 AM R.Wieser wrote: > > Hello all, > > Using Python3 I would like to import a specific class from another file (in > the same folder), and have trouble doing so. > > "from file import function" works, but fails when I try to do the same with > a class. > > "import file >

Python3 - How do I import a class from another file

2019-12-08 Thread R.Wieser
Hello all, Using Python3 I would like to import a specific class from another file (in the same folder), and have trouble doing so. "from file import function" works, but fails when I try to do the same with a class. "import file x = file.class" works, but also executes commands that are in t