These two tools that you will read here are going to increase exponentially the usability of your python scripts.

If you have read a bunch of code or you’re developing some big project and you need to do more than one script you need to know what if name== ‘main’ is. A way to write your functions only one time and use it in all of your scripts.

And if you are trying to make a program than anybody can execute the argparse library will make it efficiently for you. A way to introduce help and different arguments to your code.

if name == ‘main’:

What’s about the name variable? When the python interpreter read a source file it first defines a few special variables. In this case, name is one of them.

And the main? You’ll know that your code may have different parts. The functions you’ve defined are one of them and the other one is the main part. Usually the main is where you use your functions in order to make your code accomplish what’s been designed for. As you know well, it’s not obligated to use functions but if you need to do a concrete thing more than one time it’s very desirable to encapsulate it inside a function with a self-explanatory name. And it’s a good way to work to organize the structure of your code with all the functions above the main part. Now you’ll understand why. It will make your work easier and more readable for some stranger. And that’s always a good thing. Who knows if the stranger could be you in just a couple of months after writing the code.

#python #programming #data-science

Two Tools That Will Boost Your Python Scripts
1.80 GEEK