How do I call the double() function?
sjmachin at lexicon.net
Sat Mar 21 16:11:21 CET 2009
On Mar 22, 1:55 am, grocery_stocker <cdal... at gmail.com> wrote:
> Given the following....
> def double(val):
> return val.bind(lambda x: val.return_(x*2))
> I get "AttributeError: 'int' object has no attribute 'bind' " when I
> try to do the following
> Below is the output...
> [cdalten at localhost ~]$ python
> Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
> [GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> def double(val):
> ... return val.bind(lambda x: val.return_(x*2))
> ...>>> double(2)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<stdin>", line 2, in double
> AttributeError: 'int' object has no attribute 'bind'
How you call it is irrelevant; you already achieved that.
The problem is that your double() function is weird. ... it fails
(quite justifiably) trying to execute 2.bind(). Just as well, because
the next problem would be 2.return_() ... int objects just don't have
such methods (as the error message pointed out).
Presumably you are trying to achieve a goal that's a bit more useful
return val * 2
so perhaps you could explain what that goal is and someone may be able
More information about the Python-list