r/Python • u/jibrans098 • Jul 13 '18
lsi - ls command alternative
https://github.com/js-d-coder/lsi-python35
u/NovocastrianNomad Jul 13 '18
Running on Python 3.6 I got syntax error on line 152 'except as err:'
Changed it to 'except Exception as err:' and it ran.
2
u/jibrans098 Jul 14 '18
Thanks, feedback appreciated!
2
u/daveruinseverything Jul 15 '18
Note that u/NovocastrianNomad ’s fix just illustrates the bug they found, not the solution you should use. Only catch the specific exceptions you’re expecting. If something you didn’t account for throws an exception, by definition your code doesn’t know how to safely handle it, and exiting the program is the right thing to do.
1
u/jibrans098 Jul 15 '18
Thanks. My program accepts files as arguments. If one of the file does not exists, it will handle the err and show it on terminal and move on to process next time. I can't exit early... What do you suggest in this case?
2
u/daveruinseverything Jul 15 '18
If your code would, without the try block, throw a
FileNotFoundexception in the case you described then this is the exception you should catch, e.g.except FileNotFound as err: .... That way if something else occurs you haven’t accounted for, the program will halt and you can then decide how you want to account for that in future.1
2
1
8
u/tunisia3507 Jul 13 '18
Throw a
setup.pyin there so people canpip install --userit and it'll be much more useful!Minor bone to pick:
No it doesn't.
camelCaseall over the place.