dynamic names

Val Bykoski val at vtek.com
Sun Mar 7 14:26:18 EST 2004


I'm currently in a familiar to many business of filing my tax
return.  Being a big fan of Python and to make the process less painful, 
i started by writing my favored schedules A,B,C, and the most favored 
form 1040 in Python.  Everything was a real fun until i got to the
very famous motif "add lined Lx to Ly".
This is my naive (master)piece:

def sumL(L1,L2):
   # sum up a range of Ls
   tot=0.
   for L in range(L1,L2+1): 
      #nL=exec("L%s" % L)
      tot=tot + ("L%s" % L)
   return tot

pythonw -u "sumL.py"
Traceback (most recent call last):
  File "sumL.py", line 11, in ?
    sumL(1,4)
  File "sumL.py", line 7, in sumL
    tot=tot + ("L%s" % L)
TypeError: unsupported operand type(s) for +: 'float' and 'str'
>Exit code: 1

Any help would be life-saving.

let's-make-python-a-tax-pain-killer-ly y'rs
val



More information about the Python-list mailing list