getlist question

Victor Subervi victorsubervi at gmail.com
Fri Dec 25 04:05:34 EST 2009


On Thu, Dec 24, 2009 at 6:32 PM, MRAB <python at mrabarnett.plus.com> wrote:

> Victor Subervi wrote:
>
>  On Thu, Dec 24, 2009 at 3:28 PM, MRAB <python at mrabarnett.plus.com<mailto:
>> python at mrabarnett.plus.com>> wrote:
>>
>>    Victor Subervi wrote:
>>
>>        Hi;
>>        I have the following code:
>>
>>             try:
>>               trueVal = form.getlist(storeColNames[i])
>>               colNames.append(storeColNames[i])
>>               if len(trueVal) > 1:
>>                 trueVal = string.join(trueVal, ',')
>>
>>
>>    Unless you're using a very old version of Python, you should be using
>>    the string method:
>>
>>             trueVal = ','.join(trueVal)
>>
>>
>>                 values.append(trueVal)
>>               elif len(trueVal) == 1:
>>                 print storeColNames[i], trueVal, '<br />'
>>                 trueVal = '%s' % trueVal[0]
>>                 values.append(trueVal)
>>               if len(trueVal) > 0:
>>                 sql = '%s="%s"' % (storeColNames[i], trueVal)
>>                 sqlUpdate.append(sql)
>>             except:
>>               raise
>>
>>        This works fine except when storeColNames[i] returns no data.
>>        Now, if I were dealing with getfirst instead of getlist, I could
>>        easily put in a nonsense default data value such as '%$#' and
>>        check for that. But how can I do that or something similar (and
>>        preferably more elegant) with getlist, which takes only the one
>>        name parameter?
>>
>>    You just need to check whether len(trueVal) == 0. Simple.
>>
>>
>> The problem is that it doesn't see the value at all
>>
>>        trueVal = form.getlist(storeColNames[i])
>>        test = ','.join(trueVal)
>>        if len(test) == 0:
>>          trueVal == ''
>>  It simply doesn't register storeColNames[i] if there is nothing provided
>> from the referring page. Here's a test printout:
>>
>>  [snip]
>
>  You can see from the above part with breaks that "Availability" isn't
>> logged. But it is in the insert statement...without a value, which throws an
>> error. The complete code follows:
>>
>>  [snip]
> Try working through the code by hand for that value.


Well I've done that. What happens is the storeColNames registers the
"Availability" field naturally enough; however, as I stated before, the
getlist doesn't fetch anything because there is nothing to fetch! No such
value is passed! So, what I need to do is figure out a way to log the fact
that no value is fetched. What I have currently, unfortunately, simply
ignores the unfetchable value. As I stated before, I need to log the fact
that no such value is obtained. Please...how do I do that??
TIA,
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091225/444b9a54/attachment.html>


More information about the Python-list mailing list