feed   myspace   facebook   last.fm   send an email   twitter   tumblr   send a message via aim to graykicksass

Python

Alright so it’s been a while since I posted anything and I wanted to put something out there, while I have been working a lot on many projects I couldn’t really speak of, I have a few quick things to update you on before I get on to the main content:

First thing, the staff of Opensock have acquired MMOCCForum, this is pretty exciting and we are going to help get that place in shape.
Second, Axcid.org has had a complete rewrite of it’s API, now including keyword search. http://tunebin.info/ does a great job showing this.

Alright now onto the main content of the post:

After hating python and it’s syntax for a few years, I got the push of actually LEARNING the language, including some of it’s many libraries and functions. Once you get used to it, the syntax isn’t too bad actually. It’s actually pretty easy, for example:

import system, string """ Python block style comments """ # Python one line bash-style comments # Rather then braces for syntax blocking, python uses whitespace #Functions in python must be declared before use, unlike in javascript. # The Syntax for this is def # e.g. def SayHello(text):         # This is the body of the function         print(text) # Say Hello would be considered a 'function alias', and would be used like this: SayHello("test") # Some built in python functions string = "123" # set a variable integer = int(string) # Convert string to integer string = str(integer) # Convert integer to string # And block statements use : to start the block, e.g. if (string = str(integer)):         SayHello(str(integer))         # Else if is elif         elif (string = int(string)):         SayHello("Oh..")                 # Not gonna reach this else:         SayHello("Else reached, so none of them was correct")

Just for an example of python, Axcid’s new JSON api can be used like this:

# axcid import sys, string, urllib import simplejson as json AXCID_URL="http://two.axcid.org/new/api/?method=search.keyword&format=json&allpages=1&q=" def GetResults(query):         query = query.replace(" ", "%20")         url = AXCID_URL+query         f = urllib.urlopen(url)         obj = json.load(f)         return(obj["track"])

And the result from that:

results = GetResults("sublime") if (results):         for track in results:                 print(track["title"]+" - " + track["artist"]

Writing a IRC bot in python the other day was simple as well. And a python-spidermonkey binding exists so it would be possible to bind the syntax of JS to python, Python-Spidermoney

Anyways, that’s all for my update. Hope it was useful to someone.

Think this post is actually worth something? Why not share it?
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • StumbleUpon
  • Current
  • E-mail this story to a friend!
  • HackerNews
  • MySpace
  • Turn this article into a PDF!
  • RSS
  • Technorati
  • Tumblr

Leave a Reply