Tuesday, October 14, 2008

Python Syntax

As mentioned before, python is a simple, very functional language with thons of built in library letting you to do stuff in a short amount of time. Here are few things about python syntax and functions (think of indentation as brackets):

If statement

if myBoolean == true:
print "myBoolean is true."
else:
print "myBoolean is false."

For loop

for i in range( 0 , 10 ):
print "i = " + str( i )

While loop

i = 0
while i < 10:
print "i = " + str( i )
i = i + 1

String functions

myString = "testing123"
index = myString.find( "123" )
firstPart = myString[ :index ]
secondPart = myString[ index: ]

Cheers,
AB

Sunday, October 12, 2008

AdMatchup.com - free banner exchange service for your blog

I've just joined www.admatchup.com for free banner exchange advertisement. It is really easy to join, and I recommend it for those bloggers who like to get more traffic and advertise their blog, but don't necesarly want to spend any money doing it.

Its really easy to join, just sign up, register your website and upload your banners. Then you gotta copy paste some JavaScript of your choice (size of banner) to your blog. I've added a new HTML/JavaScript widget to my blog for it. That's about it, by doing that you'll begin advertising for others, and you'll see your banners on other websites.

Cheers,

Saturday, October 11, 2008

Python Reading Webpage

As I mentioned Python is an easy language, and you can do lots in the shortest amount of time. For example, lets say you want to read the content of a web page. If you wanted to do so in C/C++ or Java you had to go through bunch of Socket classes or more just to connect and read a web page. But here how you would do it in Python:

Open they Python editor or command line and type following:

import urllib2
resource = urllib2.urlopen("http://some url")
page = resource.read()
print page

As simple as that. In case you want to know the type of different objects just type variablename.__class__ and you'll get the type in the output window.

Cheers