if __name__ == “__main__”:

Problem:

When i started with python, i came upon this line of code a lot. Mainly in 2 contexts:
1. At the start of a file,

e1.py

2. At the end of the file to run a function which contains most of the code and to run additional tasks.

e2.py

Now the confusion usually is that everything works fine even without checking   __name__==”__main__”

Reasoning:

Every module (simply a file consisting of python code) in python has a name and statements in the module can can find out that name.

When the python Interpreter reads the source file it executes all the code found in it. But before executing the code, it defines a few special variables. If the python interpreter is running a module (our source file) as the main program, it sets the special __name__ variable to have the value __main__. If the file is being imported from another module, __name__ is set to the module’s name

Q: What if we want to run the code block only if the program was used by itself and not when it was imported from another module? This is achieved using __name__ attribute of the module.

Example:
1. Executing e2.py (image 2)
$ python e2.py
square of 2 is: 4
this program is run by itself

2. Importing e2.py
$ import e2.py
this program is being imported by another module

What it means:
1. In example 1, the source file is run directly. Hence, __name__ attribute is set to __main__ and the if condition is set to True.
2. In example 2, the source file is imported. Hence, __name__ attribute is set to “e2”. Else condition is executed thus.

Hope it helps!

 

The Beginning: Data Scientist

Hello to all.

I am Neelesh Jain. I currently work as a UX Consultant (working on a propietary software) for an MNC. May be it sounds good but I feel that as a B.Tech in CS, this is not the work i should be doing. So, a few months(may be a year, may be two, may be more) back, i started looking for other stuff as hobby which, later on, i can turn into a career.

I tried iOS Development, Graphic Designing (photoshop+illustrator, etc), Data Science (with R, then with python), IOT (internet of things: bought a raspberry pi, arduino, etc), heck in fact i even tried stock market trading where i lost a lot of money over a some period of time.

But i couldn’t stick to anyone of these above. The reason is, whenever i started on something, i started at full speed and since i had this in the back of my mind that i am 28 now (i feel i have wasted a lot of years doing nothing), i should make up for the lost time. Fairly soon i learn a lot and soon later, i things got difficult and i couldn’t keep my pace and naturally ran out steam.

This may not be totally my fault because this is the way all the online courses are made to be. The basics are simple. So it give a feeling that yes, my life is going to change now once and for all, but pretty soon, we realize that though we are going forward with the course, we are not actually learning (retaining) anything. Nor i am confident enough to apply the knowledge anywhere nor build anything on my own.

Present: Data Science
After all this, Python stuck to me. It was easy to learn + a lot of things could be done with it. I also liked Machine Learning / Data Science, because everybody is talking about it for one and second, There are a lot of job is this field (well paying too). Also, i did not want to be a stuck to R doing to Data Analysis and also after watching this video of Jeremy Achin (highly recommended).

Start of my career on Data Science with python:
I started with a lot of online courses and with the same result as stated above. But finally i found “Python for Data Science” track at Datacamp.com. It has some 20 courses in the track and i thought this is where i find my elixir. After completing first 2 courses, i was so so excited. Felt unstoppable. After 5th course, i felt again in no mans land.

My Reflections:
1. Online courses, no matter how good are useless in my case (may be useful to help someone know a field or a topic from a birds eye view). They totally fail in whatever they claim.
2. I have always tried to be a rabbit and in my case, this rabbit never completes the race. I have to be a tortoise. Be strong and calm and slow and stick to my purpose.
3. Plan for slow and a long journey. Believe in Books, Trust not in online course to Learn and Become something (may be true in Graphic design case, or iOS) but not in my case with Data Science.

Now:
I have taken a deep breath and started with python. I know that mastery in python is not required to be a data scientist, but come on. I am not going to be a master in python in 2 months. I can give it that much time (i was giving a week to python before and believe me, i felt that i knew enough). LOL!!

Will continue with my python journey in the next post.
Good Day!!