"cannot concatenate 'str' and 'list' objects" keeps coming up :(

Posted by ratce003 on Stack Overflow See other posts from Stack Overflow or by ratce003
Published on 2010-04-09T17:15:27Z Indexed on 2010/04/09 17:23 UTC
Read the original article Hit count: 389

Filed under:
|
|

I'm writing a python program and passing in a html template but an error keeps coming up, "cannot concatenate 'str' and 'list' objects" here is is the program:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgi
import cgitb
cgitb.enable()

def template(file, **vars):
    return open(file, 'r').read() % vars

print "Content-type: text/html\n"
print

form = cgi.FieldStorage() # instantiate only once!
num_1 = form.getfirst('num_1')
num_2 = form.getfirst('num_2')

int1r = str(num_1)
int2r = str(num_2)

def calc_range(int2r, int1r):
    start = range(int2r, int1r + 1)
    end = range(1, int2r)
    return start+end


int1 = int(int1r)

int2 = int(int2r)

out_str = ''

for i in range(0, int1):
    first_line_num = (int2 + i) % int1
    if first_line_num == 0:
        first_line_num = int1
    line = calc_range(first_line_num, int1)
out_str += line


print template('results.html', output=out_str, title="Latin Squares")

© Stack Overflow or respective owner

Related posts about python

Related posts about html