Saturday 22 November 2014

Getting started with Python

There are a lot of IDEs out there for developing standard (fancy) code in python. You can always follow the clearly listed out steps on their respective websites and get your favorite one set up. But hey! you are just getting started, and if you an impatient freak like myself, then you may not want to spend two hours just to install a fancy IDE and write your first "Hello World!" code. Let us do it the quick way first and then we can jump in to more serious stuff. [Pycharm 4 just got released. Yay!]

The fastest way is to get hands on something that will let you write and execute simple one line python code. IPython notebook is an obvious choice for such purposes. Below are the steps to install IPython on your windows machine:

Step 1. Get Python

Got to https://www.python.org/downloads/ and get Python 2.7.8


You may wonder why 2.7.8 and not 3.4.2. Python is currently being supported both in the legacy 2.x.x versions and the new 3.x.x versions. Here are a few reasons to still go with 2.x.x :

  • All the ready made linux distributions still have 2.x.x on them
  • More help available via documentation, blogs and stack overflow
  • And the most important one, you are a beginner and it doesn't matter! :P 

Step 2. Install setup tools


Get the installation script from https://bootstrap.pypa.io/ez_setup.py

Just run the "ez_setup.py" by double clicking on the downloaded ez_setup.py file
You shall see a window pop up like this:


Step 3. Install IPython

In command prompt type :
  •  cmd> C:\Python27\Scripts\easy_install  tornado 
  • cmd> C:\Python27\Scripts\easy_install  pyzmq
  • cmd> C:\Python27\Scripts\easy_install  jinja2
  • cmd> C:\Python27\Scripts\easy_install  ipython



Step 4. Run IPython 
  • cmd> C:\Python27\Scripts\ipython.exe notebook
  • The NotebookApp shall get started in your default web browser
  • Click on add notebook
  • Type: print "Hello World!"
  • Press Shit+Enter


                                                   


Sunday 9 November 2014

Life is short, you need python

Let us start with a dramatic background, it is always fun that way. When I was in college, they taught me how to code in C/C++. I was expected to solve the traveling salesman problem, the knapsack problem, Graph isomorphism problem etc. Like everyone else, I too was solving (copying the code from somewhere) all such problems although I had no motivation to do so.  The biggest problem probably was the nature of the problems I was banging my head against. They were simply not relevant for me then (of course these are meant to develop fundamental computer science problem solving skills, but no, I was in college and I had to be doing something cooler than that).

Maybe they should have started with something simple yet interesting. How about a piece of code that will get my friends’ birthday and contact information from social media? Or how cool would have been an assignment asking me to create a program that would download latest songs from the internet?  

Engineering students are stubborn by nature and hence they create things beating all odds and probabilities. They can’t be instructed to learn concepts and formulae. They rather have to be fooled in to creating something which they believe is cool and on their way of crafting that something, hope they’d learn.

Cooking food or doing laundry, there are essentially many correct ways of carrying out tasks human beings may have to do in their lives. For us engineers, it works in a little different way. (Warning, incoming strong opinion) There are some easy but inefficient ways of programming (which most of us including yours truly just loved to go for back in college), then there are tough but efficient ways (which are good but take a toll on the most critical resource we have in the corporate, time) and then there exist the pythonic ways (I believe if God is a programmer, he uses python). Life is too short to be coding in traditional programming languages anymore, you need python (Yes, I will get offended, find where you live and maybe tell your mom if you do not agree with me) :P

Picture Source - xkcd.com

Though this blog I intend to share the true love and whatever little experience I have with python. Keep watching this space for more!