11 Replies - 1218 Views - Last Post: 15 January 2013 - 06:16 PM Rate Topic: -----

#1 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 03:46 PM

I get this error:

'FieldStorage' object does not support item deletion.

when I try to delete an object from from fieldstorage when it tells me I can here:

http://www.modpython...util-fstor.html

Quote

clear()
Removes all form fields. Individual form fields can be deleted using the del operator.


Ok, soooooo I tried to do something like this:

form = cgi.FieldStorage()

del form['keyname']



And it fails:

TypeError: 'FieldStorage' object does not support item deletion 
      args = ("'FieldStorage' object does not support item deletion",) 
      with_traceback = <built-in method with_traceback of TypeError object>



Q: How do you delete a field from FieldStorage?

Is This A Good Question/Topic? 0
  • +

Replies To: Python cgi.FieldStorage field delete problem.

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,672
  • Joined: 13-March 10

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 04:46 PM

Could you print out the type of the "form".
i.e. do:

print(type(form))

Was This Post Helpful? 0
  • +
  • -

#3 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:35 PM

FieldStorage(None, None, [FieldStorage('username', None, 'blah'), FieldStorage('datafile', 'aspect_ratio.txt', '\noriginal height / original width x new width = new height'), FieldStorage('submit', None, 'submit')])


Was This Post Helpful? 0
  • +
  • -

#4 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:44 PM

Basically, from how I understand it is that form['keyname'] returns an object and can be treated as such. So you should be able to call something like.

del form['key']



No problem.

Or am I being a complete idiot? Hahaha
Was This Post Helpful? 0
  • +
  • -

#5 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 318
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:45 PM

On that website:

Quote

Access to form data is provided via the FieldStorage class. This class is similar to the standard library module cgi FieldStorage.

Similar to cgi.FieldStorage, not exactly the same though. cgi.FieldStorage doesn't have a delete method.

Edit: Docs for cgi module, if you need them.

This post has been edited by Simown: 15 January 2013 - 05:46 PM

Was This Post Helpful? 0
  • +
  • -

#6 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:47 PM

View PostSimown, on 15 January 2013 - 05:45 PM, said:

On that website:

Quote

Access to form data is provided via the FieldStorage class. This class is similar to the standard library module cgi FieldStorage.

Similar to cgi.FieldStorage, not exactly the same though. cgi.FieldStorage doesn't have a delete method.



So you are saying there is no way of deleting FieldStorage objects?
Was This Post Helpful? 0
  • +
  • -

#7 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 318
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:49 PM

I'm not familiar with this module, but looking at the functions it contains, I'd guess not.
Was This Post Helpful? 0
  • +
  • -

#8 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:50 PM

View PostSimown, on 15 January 2013 - 05:49 PM, said:

I'm not familiar with this module, but looking at the functions it contains, I'd guess not.



Yeah man, I've been looking all over the place.

I just want the ability to unset post vars like you could in php:

unset($_POST['blah']);


Was This Post Helpful? 0
  • +
  • -

#9 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 318
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 05:59 PM

You can remove things generally from Python structures, do you absolutely need to use cgi.FieldStore?
Was This Post Helpful? 0
  • +
  • -

#10 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 06:03 PM

View PostSimown, on 15 January 2013 - 05:59 PM, said:

You can remove things generally from Python structures, do you absolutely need to use cgi.FieldStore?


Yes, for web development. Is there an alternative to using cgi.FieldStorage to retrieve post vars, besides using a framework?
Was This Post Helpful? 0
  • +
  • -

#11 janus87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-January 12

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 06:11 PM

That is so weird because it says you can:

"Individual form fields can be deleted using the del operator."

Lies!!!
Was This Post Helpful? 0
  • +
  • -

#12 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 318
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Python cgi.FieldStorage field delete problem.

Posted 15 January 2013 - 06:16 PM

It's not that. That website is for mod_python, and not for the Python cgi module builtin. You can install mod_python and do it that way, it just acts as a fancier cgi module.

Otherwise you could do something like: create a dictionary (or similar), populate the FieldStore, delete an item from the dictionary, and use the reduced dictionary to populate a new empty FieldStore.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1