dynamic names

Discussion in 'Python' started by Val Bykoski, Mar 7, 2004.

  1. Val Bykoski

    Val Bykoski Guest

    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
    Val Bykoski, Mar 7, 2004
    #1
    1. Advertising

  2. Val Bykoski wrote:
    > tot=tot + ("L%s" % L)


    Here you seem to miss an exec - the line should probably read like this:

    tot = tot + exec("L%s" % L)

    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Mar 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy McCarthy
    Replies:
    3
    Views:
    706
    Anthony J Bybell
    Sep 24, 2004
  2. Bob
    Replies:
    1
    Views:
    381
    Lucas Tam
    Jul 30, 2004
  3. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    598
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  4. Craig
    Replies:
    0
    Views:
    441
    Craig
    Feb 9, 2004
  5. Carl
    Replies:
    0
    Views:
    521
Loading...

Share This Page