I Heart Python
I always knew about this language but I was so busy with PHP and daily work that I didn’t really get to learn it and whenever I looked at the syntax, it scared me, I didn’t want to learn another syntax so I decided to learn it later.
About a month ago, I came across Python and got a chance to play with it and I have to say WOW!
It is one of the coolest languages I’ve ever seen, the syntax is cool, the laziness is cool.
It has a great library and you can do anything you want basically.
To see some cool things, go ahead and download the Python interpreter here:
http://www.python.org/download/
Get the latest version and after you are done, run it and type these:
(Note: You will have to hit enter/return twice at the end of last line.)
import urllib2 def get_url(url, num): contents = urllib2.urlopen(url) print str(num) + " done!"
Tabs are important!
Then go ahead and type these:
for i in range(0, 100): get_url("http://www.yahoo.com/", i)
Note how clean this is, the code speaks for itself.
As you can see the output looks like this:
0 done!
1 done!
2 done!
3 done!
4 done!
5 done!
6 done!
7 done!
8 done!
9 done!
…
Now I will show you some of Python’s powers, go ahead and type these:
import thread for i in range(0, 100): thread.start_new_thread(get_url, ("http://www.yahoo.com/", i))
Wow! This is so great, imagine how much you can do with this language.
Also note that, I’m not an advance python programmer and I’m still learning but this language will take over the world one day.
The only thing about PHP is that it can be embedded inside web pages but it would be very easy to write a template engine in Python to do this.
It could be like PHP’s Smarty but with Python syntax and could compile the templates into Python scripts and run them instead of compiling every time. It would then check for the mime time of the file and would recompile if there were any changes.
I’m having so much fun playing around with Python and have never been this excited about a programming language


Jake Wharton said,
October 28, 2008 @ 3:08 pm
I’ve started delving into Python myself in the past week. I was actually thinking of porting PHPCache to Python for a web site but perhaps it would be a good first project for you since you already know the source in and out.
With regard to the embeddable Python in HTML, I had previously argued with a friend about this since I was also a Smarty user and wanted to transition that into this Python site. He argued that it was pointless to use a templating system since it all gets compiled into Python print() or PHP echo statements anyways. It is just adding another level of interpretation to your code. The seperation of presentation and logic and all those other good catchphrases were my argument but when it came down to it I caved when I realized that though PHP can be “embedded” in HTML it’s actually the opposite. You’re embedding HTML around PHP and the PHP interpreter just knows what to do with it.
I still never liked print statements 10 lines long of just HTML clogging up my code but nevertheless my friend had written a very small class which enabled you to use functions as HTML tags so instead of code like this:
print(”Titlepara1para2″)
I’m able to do this:
div(id=”hi”, h1(”Title), p(”para1″), p(”para2″))
When it comes down to it I suppose it’s a matter of preference and I still stand by all the Smarty websites I’ve done.
If you’re not interested in doing a Python port of PHPCache I would still like to go ahead with one since I find it as an incredibly useful and simple tool. Hope to see more Python posts in the future.
Codehead said,
October 28, 2008 @ 3:39 pm
Jake,
If you like we can port it to Python together, how about that?
For now though, I’m working on getting mod_python to work so I can start experimenting with web pages.
About the template engine, like Smarty, it doesn’t have to compile the template every single time, it compiles it and stores it in it’s internal cache and serves it.
It recompiles as soon as the file was changed so I there is not a lot of overhead involved and don’t you like to do something like this:
If you want to get in touch, contact me here:
http://www.hamidof.com/Contact/Contact_Hamidof/
Codehead said,
October 28, 2008 @ 3:41 pm
BTW, I have a complete design for this template engine, I will try experimenting as soon as I have some time