Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > dynamic names

Thread Tools

dynamic names

Val Bykoski
Posts: n/a
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
for L in range(L1,L2+1):
#nL=exec("L%s" % L)
tot=tot + ("L%s" % L)
return tot

pythonw -u ""
Traceback (most recent call last):
File "", line 11, in ?
File "", 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
Reply With Quote
Diez B. Roggisch
Posts: n/a
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)


Diez B. Roggisch
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting 'flat' gate level names to hierarchical names Paddy McCarthy VHDL 3 09-24-2004 05:34 PM
table field names vs. display names Bob ASP .Net 1 07-30-2004 05:06 PM
Matching attribute names to element names in a different path Carl XML 0 04-01-2004 01:15 PM
WSDL- Mapping Application Defined Names to XML Names Craig XML 0 02-09-2004 04:14 PM
XSL rules applying to XSD (XML schema) defined type names (as opposed to node names) Lewis G. Pringle, Jr. XML 0 09-30-2003 10:34 PM