for i in range(20): try: something here except IOError: pass
When python finds error in the code, it will stop and escape the loop and it might be a nightmare for us, so making an exception handler is a smart choice.
The above code is the simplest usage of try… except function, it means that, from the range(20) we will do ‘something here’, but if there are errors, here for example the error IOError is the error of not finding the object, thanks to try except, python in this case will process the ‘pass’ (forget the error and continue). So the loop is safe and can be continued.
Latest posts by Hien NGUYEN (see all)
- Change Footer Text in Slide Master in Powerpoint 2016 and later - October 28, 2019
- Proper set-up of Zotero to manage your bibliography - September 16, 2019
- Use conda package in Sublime Text to switch between Python Environment - May 7, 2019