This makes it hazardous to do the following: fs = cgi.FieldStorage(...) if fs: ... Suggestions: 1) Fix __len__; sorry, but I don't know how. 2) Create FieldStorage.__nonzero__; a hack. 3) ?
Logged In: YES user_id=469548 As far as I can tell, cgi.FieldStorage.__len__ only raises a TypeError if the FieldStorage is not indexable. It's reasonable not to support len() on an unindexable FieldStorage. I'm just wondering why you would want to do: fs = cgi.FieldStorage(...) if fs: ... Defining __nonzero__ seems reasonable if there's a reason for testing a FieldStorage for truth value.
Logged In: YES user_id=898176 For a code snippet please look at: http://mail.python.org/pipermail/python-list/2004-August/235988.html AFAIK, cgi.FieldStorage is meant to either (sort of) 'be' a list or a file after having parsed the request. So one could possibly take the builtin file object as kind of evidence: >>> f = file('/etc/passwd') >>> len(f) Traceback (most recent call last): File "", line 1, in ? TypeError: len() of unsized object >>> if f: ... print 'yes' ... else: ... print 'no' ... yes >>>