How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
I am using poplib.POP3_SSL() and I want to know what exceptions can be thrown when I instantiate it. Presumably it inherits them because there's nothing much in the documentation page for poplib.POP3_SSL(). I specifically want to trap timeout exceptions. (... and, yes, I know I should maybe move

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread dn via Python-list
On 20/12/2020 22:39, Chris Green wrote: I am using poplib.POP3_SSL() and I want to know what exceptions can be thrown when I instantiate it. Presumably it inherits them because there's nothing much in the documentation page for poplib.POP3_SSL(). I specifically want to trap timeout exceptions.

Re: dict.get(key, default) evaluates default even if key exists

2020-12-20 Thread Roel Schroeven
Ethan Furman schreef op 16/12/2020 om 17:59: Or, if the computationally massively expensive call uses potentially different arguments for each invocation: some_var = d.get('a') or cme(arg1, arg2, ...) I don't like that because it is very fragile: the expression will evaluate to the seco

Re: dict.get(key, default) evaluates default even if key exists

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-19 at 22:29:34 +0100, Roel Schroeven wrote: > What could be useful in some use cases, I think, is a wrapper function > that evaluates the function lazily: > > def dict_get_lazily(d, key, fnc, *args, **kwargs): > try: > return d[key] > except KeyError: >

Re: dict.get(key, default) evaluates default even if key exists

2020-12-20 Thread Chris Angelico
On Mon, Dec 21, 2020 at 12:47 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2020-12-19 at 22:29:34 +0100, > Roel Schroeven wrote: > > > What could be useful in some use cases, I think, is a wrapper function > > that evaluates the function lazily: > > > > def dict_get_lazily(d, key, fnc

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >I am using poplib.POP3_SSL() and I want to know what exceptions can be > >thrown when I instantiate it. Presumably it inherits them because > >there's nothing much in the documentation page for poplib.POP3_SSL(). > > Both Java and C++ have tried to i

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-20 at 16:02:53 +, Regarding "Re: How do you find what exceptions a class can throw?," Chris Green wrote: > Stefan Ram wrote: > > Chris Green writes: > > >I am using poplib.POP3_SSL() and I want to know what exceptions can be > > >thrown when I instantiate it. Presumably it inher

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 18:18:26 UTC+1, Chris Green wrote: > If I ignore the exception then the > program just exits, if I want the program to do something useful about > it (like try again) then I have to catch the specific exception as I > don't want to try again with other exceptions.

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
2qdxy4rzwzuui...@potatochowder.com wrote: > On 2020-12-20 at 16:02:53 +, > Regarding "Re: How do you find what exceptions a class can throw?," > Chris Green wrote: > > > Stefan Ram wrote: > > > Chris Green writes: > > > >I am using poplib.POP3_SSL() and I want to know what exceptions can be

Aw: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> > Remember, you get reporting (a traceback) and program cleanup and exit > > for free. What will catching an exception *add* to the user experience? > > If it's a timeout exception I'm going to delay a little while and then > try again. The timeout is probably because the server is busy. So wh

Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 19:35:21 UTC+1, Karsten Hilbert wrote: > > If it's a timeout exception I'm going to delay a little while and then > > try again. The timeout is probably because the server is busy. > > So what you are looking for is the form of a potential > "timeout exception" (s

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >So that, as is always advised, I can catch the specific exception > >being thrown! > > It usually is advisable to be more specific when catching > exceptions. The worst thing to do is surely a bare "except:" > which then ignores the exception. >

Aw: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> > So what you are looking for is the form of a potential > > "timeout exception" (say, exception name) ? > > > > Provoke one and have a look. > > > > Then catch what you saw. > > > > Programmers don't guess... I did not suggest gue

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Grant Edwards
On 2020-12-20, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > Chris Green wrote: > >>> Ultimately, it is not possible to tell what exceptions >>> a call might throw. While it may not be "ultimately possible", in practice it usually is. Most libarary documen

Re: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 19:54:08 UTC+1, Karsten Hilbert wrote: > > > So what you are looking for is the form of a potential > > > "timeout exception" (say, exception name) ? > > > > > > Provoke one and have a look. > > > > > > Then catch what you saw. > > > >

Aw: Re: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> Trust me: it takes 100x getting anything done plus keep up with your prayers, > and it takes 100^100x learning anything solid, as in just forget about it. > Indeed, consider that we are rather going to the formal verification of > programs, software, and even hardware... I sincerly wish you

list() strange behaviour

2020-12-20 Thread danilob
Hi, I'm an absolute beginner in Python (and in English too ;-) Running this code: -- # Python 3.9.0 a = [[1, 2, 0, 3, 0], [0, 4, 5, 0, 6], [7, 0, 8, 0, 9], [2, 3, 0, 0, 1], [0, 0, 1, 8, 0]] b = ((x[0] for x in a)) print(list(b)) print(list(b)) ---

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-20 at 18:25:40 -, Grant Edwards wrote: > On 2020-12-20, 2qdxy4rzwzuui...@potatochowder.com > <2qdxy4rzwzuui...@potatochowder.com> wrote: > > Chris Green wrote: > > > >>> Ultimately, it is not possible to tell what exceptions > >>> a call might throw. > > While it may not be

Re: list() strange behaviour

2020-12-20 Thread Tim Chase
On 2020-12-20 21:00, danilob wrote: > b = ((x[0] for x in a)) here you create a generator > print(list(b)) > [1, 0, 7, 2, 0] and then you consume all the things it generates here which means that when you go to do this a second time > print(list(b)) the generator is already empty/exhausted so

Re: list() strange behaviour

2020-12-20 Thread Cameron Simpson
On 20Dec2020 21:00, danilob wrote: >I'm an absolute beginner in Python (and in English too ;-) Well your English is far better than my very poor second language. >Running this code: >-- ># Python 3.9.0 > >a = [[1, 2, 0, 3, 0], > [0, 4, 5, 0, 6], > [7, 0, 8, 0, 9], > [2, 3

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Cameron Simpson
On 20Dec2020 20:34, Karsten Hilbert wrote: >> Trust me: it takes 100x getting anything done plus keep up with your >> prayers, and it takes 100^100x learning anything solid, as in just forget >> about it. Indeed, consider that we are rather going to the formal >> verification of programs, soft

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 23:16:10 UTC+1, cameron...@gmail.com wrote: > On 20Dec2020 20:34, Karsten Hilbert wrote: > >> Trust me: it takes 100x getting anything done plus keep up with your > >> prayers, and it takes 100^100x learning anything solid, as in just forget > >> about it. Indeed,

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Ethan Furman
On 12/20/20 6:06 PM, Julio Di Egidio wrote: You could have taken the chance to pay attention Programming is a *discipline*, while you keep echoing cheap and vile marketing nonsense. I am sure you do, rigour mortis eventually... Mean-spirited and hostile messages are not welcome on this

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Angelico
On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio wrote: > > Gathering evidence is indeed part of science, and computer science is > > indeed mathematics, but alas programmering is just a craft and software > > engineering often ... isn't. > > Programming is a *discipline* It's a discipline, a scie

RE: How do you find what exceptions a class can throw?

2020-12-20 Thread Avi Gross via Python-list
The original question sounded like someone was asking what errors might be thrown for a routine they wrote that used other components that might directly throw exceptions or called yet others, ad nauseum. Some have questioned the purpose. I can well imagine that if such info was available, you co

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-20 at 21:46:48 -0500, Avi Gross via Python-list wrote: [...] > I would say it is a more laudable goal for each function to publish > what interrupts they do NOT handle that might come through and perhaps > why ... I'm not disagreeing. Documenting important decisions and the reasons

Re: list() strange behaviour

2020-12-20 Thread Cameron Simpson
On 21Dec2020 08:09, Cameron Simpson wrote: >>b = ((x[0] for x in a)) > >This is a generator comprehension, and _not_ a list. I should amend this: a "generator _expression_", not comprehension. A "generator comprehension" is not a thing. Apologies, Cameron Simpson -- https://mail.python.org/ma