Deformed Form

Dave Angel davea at ieee.org
Fri Jun 11 16:09:04 EDT 2010


Victor Subervi wrote:
> Ok. Starting over. Here is the script that "generates" the variable
> "new_passengers_curr_customers":
> <snip>
>   

> Now, here's the form that *should* be able to access that variable:
>
> !/usr/bin/python
>
> import cgitb; cgitb.enable()
> import cgi
> import sys,os
> sys.path.append(os.getcwd())
> import MySQLdb
> from login import login
> import fpformat
> from New_Passengers_Curr_Customers import New_Passengers_Curr_Customers
> from New_Passengers_Addl_Customers import New_Passengers_Addl_Customers
> from New_Passenger import New_Passenger
>
> form = cgi.FieldStorage()
>
> <snip>
I have to guess here, since I have very limited CGI experience, and the 
FieldStorage() function/class isn't listed in my 2.6 docs.

But my guess is that you only get to parse the cgi stuff once.  So when 
you import another module that calls that same function, it clears it 
out so it's no longer accessible to you here.  Think of a file open.  
Once read, the file-ptr is at the end, and further reads won't see anything.

If I'm right, then you'd need something like "rewind".  Or if you just 
want this script to access the data, then move that line before the 
three imports.

Your question would have been much easier to understand if you had 
referred to "form field" rather than variable, since I assumed you 
really meant Python variable.  Also, this script is a CGI script, 
written in Python.  But the other files that you import are python 
modules, not scripts.

I'd also suggest you not use the same name for the module that you use 
for the function in that module.  That's the cause of another confusion 
I had with your message.

But back to your problem.

I'd suggest you do all your form interaction from a single script, and 
pass any needed data explicitly to functions in the other modules, 
rather than having them try to look it up themselves.

DaveA



More information about the Python-list mailing list