by simon baird

Thursday, May 22, 2008

more python vs ruby

A:

import re
line = re.compile(r'\s*#.*$').sub('',line)


B:

line.gsub!(/\s*#.$/,'')


Guess which is which. Guess which one I prefer.

(Dear readers, I realise this is boring on numerous levels. Hopefully I will get it out of my system before too much longer... ;)

Update:
A2:

line = re.sub(r'\s*#.*$','',line)

Much better. I can read that. Thanks Xavier!

2 comments:

Xavier said...

It won't change your mind, but it can be made a bit shorter:
http://docs.python.org/dev/library/re.html#re.sub
http://docs.python.org/dev/howto/regex.html#module-level-functions

xavier said...

Simon, not that I don't think that learning Python is a good think, but maybe you want to check out this:
http://agiletesting.blogspot.com/2008/05/ruby-to-python-bytecode-compiler.html...