how to append cgi FieldStorage Class instance

P

praba kar

Dear All,
I have doubt in python cgi script. I describe
that doubt with below code
import cgi
form = cgi.FieldStorage()
passwd = form['passwd'].value
print passwd
But Now I want to assign some value to form['passwd']
field value
form['passwd'] = 'surese'
Now If I try to print
print form['passwd'].value. It will raise error.
So kinldy let me how to edit or append instance
of FieldStorage class

regards
PRabahar




_______________________________________________________
Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com
 
F

Fuzzyman

praba said:
Dear All,
I have doubt in python cgi script. I describe
that doubt with below code
import cgi
form = cgi.FieldStorage()
passwd = form['passwd'].value
print passwd
But Now I want to assign some value to form['passwd']
field value
form['passwd'] = 'surese'
Now If I try to print
print form['passwd'].value. It will raise error.
So kinldy let me how to edit or append instance
of FieldStorage class

A form *isn't* a dictionary, this means that your code :
form['passwd'] = 'surese'

is wrong.
Turn the form into a dictionary and use that.
Why are you trying to assign values directly in the form ?

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python
 
F

Fuzzyman

praba said:
--- Fuzzyman said:
praba said:
Dear All,
I have doubt in python cgi script. I describe
that doubt with below code
import cgi
form = cgi.FieldStorage()
passwd = form['passwd'].value
print passwd
But Now I want to assign some value to form['passwd']
field value
form['passwd'] = 'surese'
Now If I try to print
print form['passwd'].value. It will raise error.
So kinldy let me how to edit or append instance
of FieldStorage class

A form *isn't* a dictionary, this means that your
code :
form['passwd'] = 'surese'

is wrong.
Turn the form into a dictionary and use that.

How Can I convert a form instance into dictionary
Kindly let me know.

What have you tried ? ;-)

def form_to_dict(form):
out_dict = {}
for entry in form:
out_dict[entry] = form[entry].value
return out_dict

UNTESTED AND FROM MEMORY
If it doesn't work - try reading the manual to see what I did
wrong.....
Why are you trying to assign values directly in the
form ?

To reduce variable usage in my project.

At the cost of clarity ? Not a worthwhile trade off. Explicity delet
variables you have finished with instead.

form = cgi.FieldStorage()
formdict = form_to_dict(form)
del form


Best Regards,

Fuzzy
http://www.voidspace.org.uk/python
 
Joined
Nov 1, 2006
Messages
1
Reaction score
0
I fount folowing code from a site.

if fileitem.filename:

I wanna know that why it has not used a condition along with the if statement.I know that this must be a some convensiton in python.So pls explain it a bit......
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top