Category Archives: Programming

Available Python tools for researchers

When I first start my research life, I began with Python, and I never go back. Python is powerful, simple, rich and widely supported.

In my researches, I met several problems, and I built the solution, but a lot of them are already prepared in Python.

  1. Plotting – matplotlib:
    I often use Matlab to plot my diagrams, but matplotlib is so powerful and produces nice plots. There are lots of examples that you will be able to master this package in no time. Continue reading Available Python tools for researchers

Handle Error in Python with try except

for i in range(20):
    something here
  except IOError:

 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.