1

This is a first step for my in Python on a Linux web-server using mod-WSGI.

I'm trying to get all of the cell parameters from the URL in a list like this:

...&cell=&cell=1&cell=2&cell=3&cell=4&cell=5&cell=6&cell=7&cell=8&...

So I started with code like this:

def application(environment, start_response):
    import cgi
    form = cgi.FieldStorage(fp = environment['wsgi.input'], environ = environment)
    temp_table_inputs=form.getlist('cell')

But I found that the first cell parameter is missing from the list (I presume because getlist removes it as the content is blank).

Two questions:

  • How can I get a list including the blank values?
  • How can I find which positions in the list are skipped by getlist?

Note: I know the cell stuff has a positional dependency but I'd rather look for a way to cope with that before naming the parameters according to their position (I inherited the code and quite a bit depends on the positional stuff, so renaming things will take a lot of effort).

1 Answer 1

4

According to the documentation:

The FieldStorage instance can be indexed like a Python dictionary. It allows membership testing with the in operator, and also supports the standard dictionary method keys() and the built-in function len(). Form fields containing empty strings are ignored and do not appear in the dictionary; to keep such values, provide a true value for the optional keep_blank_values keyword parameter when creating the FieldStorage instance.

Does it solve your problem?

Sign up to request clarification or add additional context in comments.

2 Comments

I'm completely new to Python, so I'm trying to get a feel for the idioms used and which parameters to set where. So thanks for pointing me to keep_blank_values. Will try and let you know.
Don't worry :) I guess all you have to do is to change this line: form = cgi.FieldStorage(fp = environment['wsgi.input'], environ = environment) to form = cgi.FieldStorage(fp = environment['wsgi.input'], environ = environment, keep_blank_values=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.