Or you could simply make your python code tail-recursive:
$ time python fib.py 40
102334155
real 0m0.013s
user 0m0.000s
sys 0m0.010s $ time python fib.py 40
102334155
real 0m0.013s
user 0m0.000s
sys 0m0.010s # 400
$ time ruby fib.rb
real 0m0.017s
user 0m0.010s
sys 0m0.006s
# 400
$ time python fib.py
real 0m0.023s
user 0m0.011s
sys 0m0.011sthat should have stated "equivalent python code"