I'm going crazy using cgi module. HELP PLEASE!!!!

Enrico Morelli morelli at cerm.unifi.it
Fri Apr 5 11:36:28 EST 2002


Dear all,

I'm going crazy using cgi module. 
Follow a main routine of a program that receives for each day of the
month, six fields from a form.

The first  'print ar'  inside of  'for' cycle, works fine, display the
correct ar contents.
The second one (outside of 'for' cycle) doesn't display nothing.
In fact,  if I try to write the array on a file, the file will be
empty.

I use python2.2 on Linux RH7.2  system.

Where I wrong??? 

I use cgi modules for more and more other forms without problems.

Thanks 

#----------------------------------------#
# Main Program
def main():

        months={1 : 'Gen',
                2 : 'Feb',
                3 : 'Mar',
                4 : 'Apr',
                5 : 'Mag',
                6 : 'Giu',
                7 : 'Lug',
                8 : 'Ago',
                9 : 'Set',
                10 : 'Ott',
                11 : 'Nov',
                12 : 'Dic'}

        MONTH_NUMBER="%m"
        YEAR_FORMAT="%Y"
        currenttime = time.time()
        nmonth=time.strftime(MONTH_NUMBER,
time.localtime(currenttime))
        year=time.strftime(YEAR_FORMAT, time.localtime(currenttime))


        print "Content-Type: text/plain\n\n"

        form = cgi.FieldStorage()


        im=int(form['month'].value)
        month=months[int(nmonth)+im]
        nmonth=int(nmonth)+im

        planningsavefile=planningsave + '-' + month
        dmonth=calendar.monthcalendar(int(year), nmonth)

        for dd in range(len(dmonth)):
                for mm in range(len(dmonth[dd])):
                        if dmonth[dd][mm] == 0:
                                continue
                        ar.append([dmonth[dd][mm],'','','','','',''])

        print ar # works fine
        for name in form.keys():

                if name=='submit':
                        continue
                 # name has the values like: 2-7 or 2-8 or 1-7b or
4-4, etc.
                d=string.split(name, '-')[0]
                s=string.split(name, '-')[1]

                d=int(d)-1
                print name, d,s # Works fine
                if s=='7b':
                        ar[d][2]=form[name].value
                elif s=='8':
                        ar[d][1]=form[name].value
                elif s=='7':
                        ar[d][3]=form[name].value
                elif s=='6':
                        ar[d][4]=form[name].value
                elif s=='5':
                        ar[d][5]=form[name].value
                elif s=='4':
                        ar[d][6]=form[name].value
                print ar # works fine

        print ar # doesn't display nothing



More information about the Python-list mailing list