dynamic names

John Roth newsgroups at jhrothjr.com
Sun Mar 7 19:47:07 EST 2004


"Val Bykoski" <val at vtek.com> wrote in message
news:a312aab6.0403071126.45582cea at posting.google.com...
> 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.

Actually, I'd put them in a dictionary, where the key is
the line number (or the form and the line number).
Then the totaling routine can check whether the line
was even entered and assume 0 if it wasn't. It's also
not that hard to set up lines with possible multiple line
items as lists in the dictionary.

Have fun with the application: it's a lot tougher
than it looks on the surface.

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





More information about the Python-list mailing list