Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 3:27 AM Akkana Peck wrote: > > Chris Angelico writes: > > Actually, only the Python interpreter has to be able to do those > > steps. That's why I put the comment *on the same line* as the import > > statement (not immediately above it, for instance). It comes out like > >

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes: > Actually, only the Python interpreter has to be able to do those > steps. That's why I put the comment *on the same line* as the import > statement (not immediately above it, for instance). It comes out like > this: > > (env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 2:46 AM Akkana Peck wrote: > > Chris Angelico writes: > > I write this as: > > > > import whois # ImportError? pip install python-whois > [ ... ] > > it means that normal exception handling is still > > happening (which might be important if I import this into something > >

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes: > I write this as: > > import whois # ImportError? pip install python-whois [ ... ] > it means that normal exception handling is still > happening (which might be important if I import this into something > else), plus it's printing the message to stderr rather than stdout [

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Rhodri James
On 18/04/2019 17:10, Manolo Martínez wrote: On 2019-04-17, DL Neil wrote: 2. When the program can still do something useful (if perhaps feature-limited) without the imported module by substituting something else in its place. Isn't this a very common scenario, similar to what

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Manolo Martínez
On 2019-04-17, DL Neil wrote: > 2. When the program can still do something useful (if perhaps > feature-limited) without the imported module by substituting > something else in its place. Isn't this a very common scenario, similar to what package management systems call "optional de

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 1:36 AM Akkana Peck wrote: > One example: there are a gazillion whois modules, and when I run my > domaincheck program on a machine where I haven't yet installed > whois, it's helpful to have a reminder of which one I should > install. (Of course, if you have one of the oth

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
DL Neil writes: > On 18/04/19 8:44 AM, Grant Edwards wrote: > > 2. When the program can still do something useful (if perhaps > > feature-limited) without the imported module by substituting > > something else in its place. > > Any (publishable) examples? One of the targets my RSS fet

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Grant Edwards
On 2019-04-18, DL Neil wrote: > On 18/04/19 8:44 AM, Grant Edwards wrote: >> On 2019-04-17, DL Neil wrote: >> >>> Do you bother with exception handling for import statements? >> >> Sometimes. There are two cases when I do that: >> >> 1. When the module has different names under Python2 and

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Gregory Ewing
DL Neil wrote: Thus the basic question: why do we (apparently) so seldom consider the possibility of an ImportError? Because the cases in which we can do something useful about it are relatively rare. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Chris Angelico
On Thu, Apr 18, 2019 at 2:32 PM DL Neil wrote: > > On 18/04/19 8:29 AM, Chris Angelico wrote: > > On Thu, Apr 18, 2019 at 6:21 AM DL Neil > > wrote: > >> Do you bother with exception handling for import statements? > >> Can we assume that if such a catastrophic error occurs, it is quite > >> acc

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Cameron Simpson
On 18Apr2019 16:05, DL Neil wrote: On 18/04/19 8:45 AM, MRAB wrote: On 2019-04-17 21:20, DL Neil wrote: Do you bother with exception handling for import statements? Can we assume that if such a catastrophic error occurs, it is quite acceptable for the code to fall-over in a tumbling-fumble?

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil
On 18/04/19 1:24 PM, Cameron Simpson wrote: On 17Apr2019 21:45, MRAB wrote: On 2019-04-17 21:20, DL Neil wrote: Do you bother with exception handling for import statements? [...] Catch only what you (well, the script) can fix. If it needs numpy, but can't import numpy, then when can it do?

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil
On 18/04/19 8:29 AM, Chris Angelico wrote: On Thu, Apr 18, 2019 at 6:21 AM DL Neil wrote: Do you bother with exception handling for import statements? Can we assume that if such a catastrophic error occurs, it is quite acceptable for the code to fall-over in a tumbling-fumble? I try/except ar

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil
On 18/04/19 8:44 AM, Grant Edwards wrote: On 2019-04-17, DL Neil wrote: Do you bother with exception handling for import statements? Sometimes. There are two cases when I do that: 1. When the module has different names under Python2 and Python3 and the program tries first one, then

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil
On 18/04/19 8:45 AM, MRAB wrote: On 2019-04-17 21:20, DL Neil wrote: Do you bother with exception handling for import statements? Can we assume that if such a catastrophic error occurs, it is quite acceptable for the code to fall-over in a tumbling-fumble? [snip] Catch only what you (well,

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil
On 18/04/19 8:53 AM, Larry Martell wrote: On 2019-04-17 21:20, DL Neil wrote: Do you bother with exception handling for import statements? I often have to do something like this: try: from settings import SITE_WAFER_DIAMETER except ImportError: SITE_WAFER_DIAMETER = 300 That's an

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Cameron Simpson
On 17Apr2019 21:45, MRAB wrote: On 2019-04-17 21:20, DL Neil wrote: Do you bother with exception handling for import statements? [...] Catch only what you (well, the script) can fix. If it needs numpy, but can't import numpy, then when can it do? Might as well just let it fail. I'm of thi

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Larry Martell
On 2019-04-17 21:20, DL Neil wrote: > Do you bother with exception handling for import statements? I often have to do something like this: try: from settings import SITE_WAFER_DIAMETER except ImportError: SITE_WAFER_DIAMETER = 300 -- https://mail.python.org/mailman/listinfo/python-list

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread MRAB
On 2019-04-17 21:20, DL Neil wrote: (I know it's not Friday [exp], and after personal apologies[apo]) Do you bother with exception handling for import statements? Most of the code I read, both in books and during code review, eschews any form of ImportError check. Even data science people who

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Grant Edwards
On 2019-04-17, DL Neil wrote: > Do you bother with exception handling for import statements? Sometimes. There are two cases when I do that: 1. When the module has different names under Python2 and Python3 and the program tries first one, then the other. 2. When the program can still do

Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Chris Angelico
On Thu, Apr 18, 2019 at 6:21 AM DL Neil wrote: > > (I know it's not Friday [exp], and after personal apologies[apo]) > > > Do you bother with exception handling for import statements? > > > Most of the code I read, both in books and during code review, eschews > any form of ImportError check. Even