if __name__ == ‘main’ and argparse (+ bonus) .Two tools that will boost your Python scripts.
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.
🔵 Intellipaat Data Science with Python course: https://intellipaat.com/python-for-data-science-training/In this Data Science With Python Training video, you...
In this tutorial, we'll learn Must-Know Data Science Libraries in Python. Python is the most widespread and popular programming language in data science, software development, and related fields. The simplicity of…
In Conversation With Dr Suman Sanyal, NIIT University,he shares his insights on how universities can contribute to this highly promising sector and what aspirants can do to build a successful data science career.
Enroll in our Data Science with Python training in Chennai. Best Data Science with Python Training courses in Chennai for 100% Job Placements Support.
🔥Intellipaat Python for Data Science Course: https://intellipaat.com/python-for-data-science-training/In this python for data science video you will learn e...