Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

try except and programming etiquette

Tags:

python

I'm making a GUI and I'm finding myself to be using a lot of try except statements. My question is, should I be redesigning my program to use less try except statements or is try except a good practice to be using in python programs? I like them because they're informative and make debugging, for me, easier. Just wondering what real developers think about it.

Thanks

like image 222
Jeff Avatar asked Dec 12 '22 07:12

Jeff


1 Answers

One of Python's idioms is: It's easier to ask for forgiveness than for permission. (Python Glossary, have a look at EAFP).

So it's perfectly acceptable to structure program flow with exception handling (and reasonably fast too, compared to other languages). It fits Python's dynamic nature nicely imho.

like image 92
ChristopheD Avatar answered Dec 29 '22 00:12

ChristopheD