Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Chris Angelico
On Tue, Nov 5, 2019 at 6:26 PM R.Wieser wrote: > > It is considered totally OK to use exception handling as a control > > flow mechanism in Python. > > I'm not sure what exactly you mean with "a control flow mechanism", but as > several methods throw exceptions themselves I will have no choice in

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Luciano, > In this context, what I mean by that quote is to say that Python > never forces you to wrap anything in try/except blocks. True. But /not/ doing it means that the casted exeption in the __init__ block will just abort the whole program - in a user unfriendly way. And thats normally

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Chris Angelico
On Tue, Nov 5, 2019 at 5:43 PM dieter wrote: > I suppose that "isinstance" (at least under Python 2) does not > behave exactly as stated in PEP 3119. Instead, "isinstance" > first directly checks for the instance to be an instance of the > class *AND ONLY IF THIS FAILS* calls the class' "__instanc

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread dieter
Veek M writes: I simplify your code to demonstrate what goes on: >>> class MA(type): ... def __instancecheck__(cls, inst): ... print "MA", cls, inst ... >>> class AM(list): __metaclass__ = MA ... >>> am = AM() >>> isinstance(am, AM) True As you can see, even with a class (rather than a tu

Re: Is there some python libary for edit iso file drectly?

2019-11-04 Thread Michael Torrie
On 11/4/19 4:11 PM, Hongyi Zhao wrote: > Is there some python libary for edit iso file drectly? Isn't an ISO image a read-only sort of thing? If you want to modify files don't you have to create a whole new image? -- https://mail.python.org/mailman/listinfo/python-list

Fwd: permission denied using python 3.8

2019-11-04 Thread Francois van Lieshout
Outlook voor Android downloaden Van: Francois van Lieshout Verstuurd: maandag 4 november 2019 18:19 Aan: python-list@python.org Onderwerp: permission denied using python 3.8 Hi, i installed python 3.8 the latest version but it doesn’t wo

Re: What's the difference between running a script under command box and interpreter?

2019-11-04 Thread jfong
Grant Edwards於 2019年11月5日星期二 UTC+8上午12時41分24秒寫道: > On 2019-11-04, Dennis Lee Bieber wrote: > > Using > > > >from module import * > > > > is often the worst thing one can do. > > I agree 100%. > > Unfortunately, most of the official standard library documentation is > written assuming you do

Is there some python libary for edit iso file drectly?

2019-11-04 Thread Hongyi Zhao
Is there some python libary for edit iso file drectly? -- https://mail.python.org/mailman/listinfo/python-list

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Peter J. Holzer
On 2019-11-04 14:54:23 +, Rhodri James wrote: > On 04/11/2019 14:33, Veek M wrote: > > __metaclass__ = whatever; # is python2.x syntax > > But not Python3: see PEP 3115 Doesn't "X is python2.x syntax" imply "X is not python3 syntax"? hp -- _ | Peter J. Holzer| Story must ma

Re: Friday finking: TDD and EAFP

2019-11-04 Thread Peter J. Holzer
On 2019-11-03 18:51:25 -0500, Terry Reedy wrote: > On 11/3/2019 3:44 PM, Peter J. Holzer wrote: > > > On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: > > > Agreed: (in theory) TDD is independent of language or style. However, I'm > > > wondering if (in practice) it creates a mode of t

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Luciano Ramalho
On Mon, Nov 4, 2019 at 5:52 PM R.Wieser wrote: > I was thinking of (the needed) wrapping of the "newObject = classObject()" > line in such a try..except block (to capture the re-casted exception). I > take it that that that means that the full contents of the __init__ block > are wrapped too. P

Re: What's the difference between running a script under command box and interpreter?

2019-11-04 Thread MRAB
On 2019-11-04 21:05, Peter J. Holzer wrote: On 2019-11-03 16:34:39 -0800, jf...@ms4.hinet.net wrote: I innocently thought that when import module through "from test import *", I am working on test's globals under REPL. I didn't noticed the REPL has its own globals. Well, you imported every glo

Re: What's the difference between running a script under command box and interpreter?

2019-11-04 Thread Peter J. Holzer
On 2019-11-03 16:34:39 -0800, jf...@ms4.hinet.net wrote: > I innocently thought that when import module through "from test import > *", I am working on test's globals under REPL. I didn't noticed the > REPL has its own globals. Well, you imported every global from test. So you are (kind of) workin

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Rob, > That's why if you for instance, open a serial port in an __init__ routine, > and something fails, you want to catch the exception there in __init__, > explicitly close that serial port, and reraise the exception. Otherwise > that port still has an object open against it until Python gets

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 10:59 AM, R.Wieser wrote: Rob, Returning None will specifically NOT accomplish the thing you want; nothing ever checks the return value of __init__. I thought to have read that when you return a none from it the object itself would return a placeholder singleton. Raise an excepti

Re: What PEPs are worth reading after you've read a textbook/Beazley but want to understand details/innerworkings

2019-11-04 Thread Chris Angelico
On Tue, Nov 5, 2019 at 3:16 AM Veek M wrote: > > sez it all really, among the Finished PEPs, which ones should I pore > through to teach Python competently! > > What PEPs are considered de rigueur? What PEPs do you guys consider note- > worthy? > > https://www.python.org/dev/peps/ That's a really

Re: Trouble trying to get started with pygame

2019-11-04 Thread MRAB
On 2019-11-04 05:21, originallmo...@gmail.com wrote: On Sunday, November 3, 2019 at 9:40:05 PM UTC-5, MRAB wrote: On 2019-11-04 01:52, originallmo...@gmail.com wrote: > On Friday, November 1, 2019 at 11:17:42 PM UTC-4, MRAB wrote: >> On 2019-11-02 02:28, originallmo...@gmail.com wrote: >> > I tr

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Luciano, > """A failed __init__ should raise an appropriate exception. A bare > return or returning None is what any __init__ is expected to do in the > normal case, so it signals success.""" Ah, that settles it than. Somehow I thought that a return (of "none") there indicated an error result,

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Rob, > Returning None will specifically NOT accomplish the thing you want; > nothing ever checks the return value of __init__. I thought to have read that when you return a none from it the object itself would return a placeholder singleton. > Raise an exception. Yeah, that was what I was thi

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 10:36 AM, Luciano Ramalho wrote: Sorry, I responded only to the OP. My response: """A failed __init__ should raise an appropriate exception. A bare return or returning None is what any __init__ is expected to do in the normal case, so it signals success.""" Actually, the Python inter

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Luciano Ramalho
Sorry, I responded only to the OP. My response: """A failed __init__ should raise an appropriate exception. A bare return or returning None is what any __init__ is expected to do in the normal case, so it signals success.""" Actually, the Python interpreter *does* check the return of __init__. If

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 7:32 AM, R.Wieser wrote: Hello all, The whole question: How should I handle failed initialisation code inside the __init__ of an object ? I've seen an example doing a plain "return" (of the value "none""), but have no idea if that is all it takes. Also, I wonder what happens to the

Re: What's the difference between running a script under command box and interpreter?

2019-11-04 Thread Grant Edwards
On 2019-11-04, Dennis Lee Bieber wrote: > Using > >from module import * > > is often the worst thing one can do. I agree 100%. Unfortunately, most of the official standard library documentation is written assuming you do _exactly_that_. Though it makes the documetnation more succinct, I thi

What PEPs are worth reading after you've read a textbook/Beazley but want to understand details/innerworkings

2019-11-04 Thread Veek M
sez it all really, among the Finished PEPs, which ones should I pore through to teach Python competently! What PEPs are considered de rigueur? What PEPs do you guys consider note- worthy? https://www.python.org/dev/peps/ -- https://mail.python.org/mailman/listinfo/python-list

OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Hello all, The whole question: How should I handle failed initialisation code inside the __init__ of an object ? I've seen an example doing a plain "return" (of the value "none""), but have no idea if that is all it takes. Also, I wonder what happens to the object itself. Does it still exist

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-04 Thread R.Wieser
Rhodri, > Yes, it can. That's why you want to create a finalizer to tidy up. AFAIKS in my case there is nothing to cleanup. As far as I understood the WeakSet will automagically purge the reference whe the object it references is destroyed. I could also try to do it in in the __del__ method

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James
On 04/11/2019 14:33, Veek M wrote: Aha. You're trying to fix up the metaclass after the fact, which is not the right way to do it. If you change the class definitions to: __metaclass__ = whatever; # is python2.x syntax But not Python3: see PEP 3115 then you get the prints from MyMeta.__i

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Veek M
> > Aha. You're trying to fix up the metaclass after the fact, which is not > the right way to do it. If you change the class definitions to: > __metaclass__ = whatever; # is python2.x syntax > then you get the prints from MyMeta.__instancecheck__(). The > isinstance() still returns True, tho

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James
On 04/11/2019 11:30, Veek M wrote: 1. Why do I get True whenever i tuple the isinstance(f, (Bar, Foo)) (and why don't the print's run) I'm not very familiar with metaclasses, but I can answer the second part of your question. The docs say that you can feed it a tuple and that the results a

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-04 Thread Rhodri James
On 02/11/2019 06:30, R.Wieser wrote: Rhodri, Use weak references. A WeakSet (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is probably what you want. Most likely!As a fresh freshling in regard to python I was not even aware that a "copy object, but do not increment the

Re: Congratulations to @Chris

2019-11-04 Thread Mario R. Osorio
On Thursday, October 24, 2019 at 4:29:59 PM UTC-4, Chris Angelico wrote: > On Fri, Oct 25, 2019 at 7:20 AM DL Neil via Python-list > wrote: > > > > Chris Angelico: [PSF's] 2019 Q2 Community Service Award Winner > > http://pyfound.blogspot.com/2019/10/chris-angelico-2019-q2-community.html > > > > .

__instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Veek M
1. Why do I get True whenever i tuple the isinstance(f, (Bar, Foo)) (and why don't the print's run) The docs say that you can feed it a tuple and that the results are OR'd The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for isinstance(x, A) or isinstance(x, B) or ... (etc.