…little BITS of our lives.

Hey Reader!

How have you been doing?
Wow, it’s been so many years since I wrote anything here. In this period, I have grown up from a teenager, learnt many new things, technologies, and forgotten some too, for the good!

As I sit wondering about new ways to hack time, I see this as a new opportunity. To pose as a newbie, to pretend to forget everything I know about python, and learn it all over once again! But, that would be a dry thing to do! No fun at all.

So, let’s spice it up! Every week starting next Monday, I will learn enough python, to implement a simple project. The idea is to develop a portfolio of some good projects, which everyone can try to implement on their own. Since, the time period is a bit small, so the projects will often range from simple to mid level difficulty, but the very idea of this, already gives me goosebumps.

I no longer have the luxury of the free time I used to have as a college student, but pushing the limits and having fun along the way, is what I wanted this blog to be about.

Wanna join me in this ride? Welcome aboard!

The next three days, I will update this blog, add some new features and then our journey will begin!

Hi again! This time, a friend of mine asked me to install pygame on his fedora machine to work with python3. Now I don’t have much experience with fedora, but I kinda liked it in the little time I have used it.

Anyways, coming back to the topic, this installation, took my entire afternoon, so I decided to make a post about it.

Fedora is shipped with python2 installed already, so the first thing is to install python3. Now since you are reading this, I will assume you already have python 3 installed.

What you should do is also install the ‘python3-devel’ package. Why?

Because if you don’t, somewhere down the line, your installation progress will stop by an error such as the following:


So, fire up the command line and type in the following:

yum install python3-devel

Oh, one more thing! Do this as root user, but ur system probably already told u that. 😉

Once you are done, we have to install all the dependencies for pygame. These are basically some libraries, some of which might be present in your system already.

Anyways, go ahead and type in:

yum install SDL SDL-devel smpeg smpeg-devel portmidi portmidi-devel ffmpeg ffmpeg-devel

This will install the dependencies that you need in order to install pygame. Now, what we need to do is acquire pygame. You can do this by any method, for example by downloading the zipped file from the pygame website and then extracting it into your computer.

I prefer the method of acquiring pygame through ‘svn‘. Unfortunately, svn might not be installed on your computer. So, you can stick to other methods or ‘install svn’ :D.

If you don’t know what svn is, google it and you will get introduced to something really awesome! Moving ahead, if you decide to install svn, you can do this by:

yum install subversion

Now go and acquire pygame by typing this into your command line.

svn co svn://seul.org/svn/pygame/trunk pygame

The download will begin in a moment, you will see a bunch of text appearing and then when the prompt comes again, move to the pygame folder.

cd pygame

Then type:

python3 config.py

python3 setup.py build

Sometimes an error pops in here, saying something like it can not find ‘-lporttime’. In order to resolve this issue, you just have to create a symbolic link to lportmidi as follows:

Move to /usr/lib

cd /usr/lib

Then type:

ln -s libportmidi.so.0 libporttime.so

For this one line I have this guy to thank: Vzades’s Blog 🙂

And then, just enter

python3 setup.py install

And you are done!!!

Happy times are back again, And I can go back to sipping my cola !!! 😀 😀

Fedora, ur ON!

Well it is time for another easy tutorial on how to install something with python on Windows and that something is pyserial. I am assuming if you are reading this, you already know what pyserial is, but are just having trouble getting it installed with python.

Let me just talk about what problem most people face while performing the install. They get an error like “no python installation found in the registry” and then the installer quits.

To resolve this error, first you need to check whether your windows machine can find the python executable, by which I mean the following:

1. Open up the command prompt and type python.

If you get an error like “python is not recognized as an internal command…bla bla bla…” it means that your     system can not find where your python executable is. We need to solve this issue first and for that we need to set our ‘environment variables‘.

2. So go to Start menu. Right click on computer and select properties. Then go to advanced system properties and select environment variables. Look for the variable ‘Path’, select it and click edit. Python 3.2 is installed in the location ‘C:\Python32‘, so just add this to the path variable.

3. Now close all windows and RESTART your computer. If you don’t restart it, then the changes won’t take place.

4. Now after restarting, to check all if all went well, open the command prompt and then type ‘python‘. What you should get is following:

This prompt tells us that the system can find python executable now. Yay!!! Now we can focus on installing pyserial.

So the next step involves downloading the  file  pyserial-2.6.tar.gz from the pyserial website, extract it and then copy the extracted folder to C:\Python32\Lib\site-packages. Once you are done with that, move to the folder which contains the file ‘setup.py’, using command prompt and enter:

python setup.py install

That’s it!

Have fun with pyserial, and if u have any problems pls post. I will be happy to help! 😀

Finally the long break ends!

Hello again!

I have not been writing much here lately because… umm.. I dunno.
But recently I joined a udacity course on python which has prompted me to make some more interesting posts, which will be coming out soon! Till then, chill and have fun 😀

Okay so finally I got the time to tell you about the coolest calculator in the world – “The Python Shell“.

You might not agree with me now, as you might be in the habit of working with those handy little gadgets you can put in your pocket and carry anywhere.
But let’s talk about Python and you will start liking it before you know it!

(Before reading the stuff below, make sure that you have python (preferably python3) installed on your computer).

Okay, so you have it! Good, lets proceed.

1. Fire up the Python shell…

How, you say?

Well, if you are on a linux machine, press alt-F2 and then type “idle”. Go ahead, do it!

And you will see something like this…

The Python Shell

For a windows machine, just go to the start menu and type “idle” and press “enter”. And you will be all set to dive into the python world.
Sorry for the mac users, I am not as rich as you are, but there are loads of content on internet to guide you.

Anyway, the screen you see in front of you is the “python shell” or our cal-cool-lator.

One of the things to notice is the “>>>” sign. That is just your command prompt which indicates that “hey dude! you can type your command here”.

2. What does it do?

Well everything a calculator can…

Just type in “2 + 2” and see what happens…

“So python shell can add 2 numbers, big thing, huh? Can it multiply or divide or subtract?”, you say.

Well ofcourse it does! Just go ahead and type in some expressions you enter in your calculator and see the magic happen.

To get yourself started, you can use the following expressions :
1) 4 – 3
2) 8 * 3
3) 17 / 10
4) 5 – 100
5) 3 * -1
6) 123 / -123
Note down what results your shell gave you and match them with the image below:
To enlarge the image just click on it.

The Python Shell

Okay now, did you check out a few interesting things so far?

You did? Well, cool! and if you didn’t don’t worry, but from next time be on the look out for peculiar things.

1. The text you type appears in color “black” but the answer appears in “blue”. LOL!!!

2. The important thing: Python shell can do floating point division automatically. Well, python3 can. In python2 if you type 17 / 10, the answer will be 1, because most programming languages out there, truncate the decimal part if you don’t explicitly specify it to be a floating point calculation.

To get the same result in python2, you should type 17.0 / 10.0, but in python3 all’s well!

You: “But my calculator can find a log! a square root!Can python do that?

Me: “Go try that out! To find the square root, you have to use the sqrt() function. Go try it!
Do it first and only then read it.

You: “When I try to do that in python shell, it gives an error message like this(see image) and it blows my brains out! What the hell is a NameError man! And what is traceback? I am not using it till you teach me how to do stuff like finding root of a number!“.

Traceback Error

Well, my friend!
Python shell can do that too. All that’s needed is that you know how to do it.

Now getting square root or a log is a little advanced maths and so python hides it from you till you demand that from it. Pretty Economical, I will say!

Just type the following line in the shell and press “enter”.

import math

Now type in math.sqrt(number)
Note: for number choose a value like 4 or 10 or 2.5.
Press enter and see the magic happen.

Similarly, you can calculate the log of a number.

Just type in math.log(number, base) and press enter. See the example below:

Square root working properly

There are many more complex functions that python shell “The Calcoolator” can do, but those are for later times!

What I want to do is explain the error that you got when you tried to find the square root using the sqrt function.

The answer is that python has a rich set of built in library functions, but to use them first you gotta tell it that “hey Mr. python! I need to calculate the square root of a function. So I wanna use that function you have…what’s that called?…umm… yeah, the sqrt() one.
But python says,” I know I have such a function, but my collection is so big, you know! You need to help me locate where that function you need is”.
And hence python gives the “NameError”

You do that by typing in “import math” which is the library containing the function sqrt() and then python gives you the green signal to go ahead and use it whichever way you want to, which of course, is to calculate the square root.

And about the traceback thing!

Python is an interpreted language, and it executes your code line by line, without checking if your code is completely right. So if there is an error, it does a ‘traceback’ and tells you which line it found the error in!!!

One final and VERY IMPORTANT thing!

Python is a language which uses indentation to identify blocks of code:

If you don’t know what that means, don’t worry, we will deal with it later. Just make sure, you don’t leave any space after the “>>>” (called ellipsis), otherwise you will get an error like this:

I hope things I explained are clear. If there are any queries, feel free to comment or mail me to ask your questions.
Next up, we will deal with comparisons, strings and text. But that’s for next week! Hah! Too much typing already!
So go ahead and have fun with PYTHON!

Okay, so I struggled for about an hour trying to get ‘ pygame ‘ run with Python 3 on my ubuntu 11.04 machine, so I decided to write a post about it.
By default, Ubuntu ships with Python 2.7 installed, so pygame gets installed with python 2.7.
To install it with python3, do the following:
1. Open up the terminal and type the following code:
sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev
2. Then once all libraries are downloaded and installed, type:
svn co svn://seul.org/svn/pygame/trunk pygame

cd pygame

python3 setup.py build

sudo python3 setup.py install

3. That’s all! You can now run pygame with python3.

I have also updated this on the pygame website, so that no one falls into this trouble again! 😉


Am I nuts trying to get you something which “Discovery” hasn’t got covered yet?

No, No! Not at all! Snakes sure are scary creatures, but our Python is one of the friendliest out there, totally harmless and always a delight to talk to. I will let you see, what our python looks like.

Although it seems that there are two snakes, one blue and the other yellow, Python is neither of them. It is a programming language.
Read more about its history here: http://en.wikipedia.org/wiki/Python_language

So? Did you read that? Really?

I bet most of you decided to skip over that. After all, if Wikipedia has all the content, what’s this tutorial gonna do!
Well, we will talk about Python here as well, but it is a good idea to be sure that the thing is really worth giving some time, ’cause if it happens to be a snake that’s being talked about, well, not truly my taste…!
Anyway, even if you skipped the content at wikipedia, here’s the basic thing you need to know before starting out with Python.

Python is an interpreted programming language that has become the language of choice at various places (Google for example) because of its simplicity and the power which allows it to do almost anything.

Well, Lets get started then!

We will be talking about Python 3. Yes, the number 3 stands for the version. In the computing world, whenever a software is released, it is enhanced over time, bugs are removed, interfaces are improved and lots of other modifications are done to better suit the needs of the user. The software is released again and that number there helps identify the newer version from the older ones.
The latest version is Python 3.2.1.

Someone out there: Wow! So, Python is actually not a snake, but a software living inside my computer. Now I
trust you,tell me more.

Yes, Python is a software, a programming language. (that’s what I had been saying for so long!) But it does not live inside your computer already, unless you are using LINUX or MAC OS. So, let’s give Python a home.

    Go to the website: http://python.org and then click on their downloads section.
    Depending upon your OS, choose your installer of Python. (remember version 3.2.1)
    Download and install it.

That should have been simple.
So what have we got by doing that?
More on that later. I gotta run now! Also I think it would be better if I made a video about the stuff I wanna teach. Really? teach?