Sunday, March 18, 2007

Converting Ruby Code to Python Code

The following are the basic fundamentals

  • All code must be properly indent
  • After class definition a ":" is required
  • After every method definition a ":" is required
  • Code does not use "end", so remove them all
This are some minor changes in python compare to ruby

  • true = True
  • false = False
  • nil = None
  • elsif = elif
  • There are no && nor || but only "and" and "or"
  • initialize does not exist, you need __init__(self):

Sample code converted from Ruby to Python:
Click Here to download

1 comment:

daveangel said...

This shows that Python is way more readable than Ruby. I can look at the code example and tell instantly what the python code does not so with the funky Ruby!