weird python issue

0 views
Skip to first unread message

mdipierro

unread,
May 31, 2009, 10:58:26 PM5/31/09
to web2py Web Framework
does anybody understand this?

massimo-di-pierros-macbook:web2py mdipierro$ python web2py.py -S
welcome
>>> print INPUT() or 'oops'
oops

why is INPUT same as False?

Massimo

DenesL

unread,
May 31, 2009, 11:27:41 PM5/31/09
to web2py Web Framework
Reposting from http://groups.google.com/group/web2py/browse_thread/thread/2114e5ab590fc228#

From the python 2.5 manual, library reference, 3.1:

"The following values are considered false:
...
instances of user-defined classes, if the class defines a __nonzero__
() or __len__() method, when that method returns the integer zero or
bool value False."

Both INPUT and A derive from DIV which has a __len__ method defined as
len(self.components).
INPUT's len is zero while A's is one, so combining that with the 'or'
in sqlhtml rev979 line 319 gives the above mentioned results.

Denes

mdipierro

unread,
May 31, 2009, 11:35:12 PM5/31/09
to web2py Web Framework
thanks. I forgot DIV had a len method.

Massimo

On May 31, 10:27 pm, DenesL <denes1...@yahoo.ca> wrote:
> Reposting fromhttp://groups.google.com/group/web2py/browse_thread/thread/2114e5ab59...
Reply all
Reply to author
Forward
0 new messages