Monday, January 21, 2008

Real-life Python

I just came home all tired and the minute I saw the place it hit me---I didn't
tidy up in ages. There were books everywhere, clothes all over the place, dirty
dishes... As I'm always tired when I come home from work, I never feel like cleaning
the place up. Somehow Python came up in my head as the solution to my problem (well,
not really a solution:) ). What if we could execute Python code in real life. I
mean, wouldn't it be great if we could do something like:


apartment.sort()
dishes.wash()

As I of course didn't feel like cleaning, I decided I'd better spend my time writing
about how I would use Python in real life. Beside cleaning the house, I think Python
could be of great help in the following problems as well.

Understanding women
Did you ever have a fight with your girlfirend/wife (it's a rhetorical question,
of course you did)? Did you ever wonder "What is going on in that mind of hers"?
Well, think about this one:

print girlfriend.__doc__

And if that didn't help, wouldn't it be great to be able to do something like

import dis
print dis.dis(girlfriend.think)

This would not only help you understand her, but also enable you to predict how
will she react. That's right, no more "What did I do wrong"---just look at the
code and you will know.

The answer to life
For all those in doubt as to whether they are wasting their life going to church
every Sunday, here's an ellegant Pythonic solution:

import time
if life.endswith(death):
while alive:
party()
time.sleep(12*60*60)
die()
else:
import random
religions = [christianity, islam, buddhism, hinduism]
myReligion = random.choice(religions)
for day in allDays:
if day != sunday:
be_humble()
else:
repent_sins(myReligion)
#no more days, end of time is here
go_to_heaven(myReligion)


What would you use Python for in real life?






No comments: