On 16/04/2006 10:28 AM, Kun wrote: > I am trying to make an if-statement that will not do anything and print > 'nothing entered' if there is nothing entered in a form. I have the > following code that does that, however, now even if I enter something > into the form, the code still outputs 'nothing entered'. This violates > the if statement and I am wondering what I did wrong. > > if form.has_key("delete_id") and form["delete_id"].value != "" and
Unless your code needs to run on Python 2.1, consider using the <key> in <dict> construct instead of <dict>.has_key(<key>) -- it's not only less wear and tear on the the eyeballs and fingers, it's faster. Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32 >>> foo = {}; foo['bar'] = 'zot' >>> foo.has_key('bar') 1 >>> 'bar' in foo Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: 'in' or 'not in' needs sequence right argument >>> Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32 >>> foo = {}; foo['bar'] = 'zot' >>> foo.has_key('bar') 1 >>> 'bar' in foo 1 >>> -- http://mail.python.org/mailman/listinfo/python-list