Re: [Tutor] TypeError: 'int' object is not callable

2012-05-16 Thread René Bastian
Le Wed, 16 May 2012 14:37:53 -0600,
Modulok  a écrit :

> On 5/16/12, Greg Christian  wrote:
> > Can anyone tell me what I am doing wrong here. When trying to call
> > the factors function from main with x = factors(Tn), getting the
> > error message: “TypeError: 'int' object is not callable”? Any help
> > would be appreciated. Thanks.
> >
> >
> > def factors(n):
> > L = []
> > for i in range(1, int(n ** 0.5) + 1):
> > if (n % i == 0):
> > L.append(i)
> > return L
> >
> > def main():
> > factors = 0
> > counter = 0
> > L = []
> > while len(L) < 50:
> > counter += 1
> > L.append(counter)
> > Tn = sum(L)
> > x = factors(Tn)
> > #print x
> > print(sum(L))
> >
> >
> > if __name__ == '__main__':
> > main()
> 
> You declared 'factors' as a variable on line 1 in main::
> 
> factors = 0
> 
> This masks the call to the function 'factors'. You get the error
> because you assigned factors an integer and you cannot 'call' an
> integer. The easiest solution is to use another name for the variable
> 'factors' instead.
> 
> -Modulok-

If you use 'pylint', a syntax checker, you get this:

C:  1,0: Missing docstring
C:  1,0:factors: Missing docstring
W:  9,4:main: Redefining name 'factors' from outer scope (line 1)
C:  8,0:main: Missing docstring
E: 16,12:main: factors is not callable
W: 16,8:main: Unused variable 'x'


> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 



-- 
René Bastian
www.pythoneon.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TypeError: 'int' object is not callable

2012-05-16 Thread Emile van Sebille

On 5/16/2012 1:17 PM Greg Christian said...

def factors(n):
 L = []
 for i in range(1, int(n ** 0.5) + 1):
 if (n % i == 0):
 L.append(i)
 return L


... now you've completed defining the function factors...


def main():
 factors = 0


... and here you create an integer of the same name...


 counter = 0
 L = []
 while len(L) < 50:
 counter += 1
 L.append(counter)
 Tn = sum(L)
 x = factors(Tn)


... and here you attempt to call the interger factors passing it the 
argument Tn



 #print x
 print(sum(L))



Also, in the future please post the complete traceback  -- it relly helps.

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TypeError: 'int' object is not callable

2012-05-16 Thread Modulok
On 5/16/12, Greg Christian  wrote:
> Can anyone tell me what I am doing wrong here. When trying to call the
> factors function from main with x = factors(Tn), getting the error message:
> “TypeError: 'int' object is not callable”? Any help would be appreciated.
> Thanks.
>
>
> def factors(n):
> L = []
> for i in range(1, int(n ** 0.5) + 1):
> if (n % i == 0):
> L.append(i)
> return L
>
> def main():
> factors = 0
> counter = 0
> L = []
> while len(L) < 50:
> counter += 1
> L.append(counter)
> Tn = sum(L)
> x = factors(Tn)
> #print x
> print(sum(L))
>
>
> if __name__ == '__main__':
> main()

You declared 'factors' as a variable on line 1 in main::

factors = 0

This masks the call to the function 'factors'. You get the error because you
assigned factors an integer and you cannot 'call' an integer. The easiest
solution is to use another name for the variable 'factors' instead.

-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-18 Thread Jacob S.
Thanks for the explanation!
Jacob Schmidt


> Jacob S. wrote:
> > Thank you!
> >
> > Wait, though.
> >
> > How do I do this?
> >
> > def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
> > **kwds?
>
> Call it what you like, it's an ordinary function parameter. kwds is
commonly used but you can use
> kwargs.
> > print kwargs
> > another(kwargs)
>
> Should be another(**kwargs). If you call another(kwargs) then kwargs will
be an ordinary parameter
> of another and another would be defined as
> def another(kwargs):
>...
>
> >
> > def another(**kwargs):
> > for x,y in kwagrs.items():
> > print "%s = %s" % (x,y)
> >
> > a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
>
> Should be a dict, the **kwds parameter is a dict mapping keywords to
values
> a = {'a':2, 'f':3, 't':[1,2,3]}
>
> There really are two different and complementary things going on here, at
the point of call and at
> the point of function definition.
>
> At the point of call, you can pass a dictionary instead of using explicit,
named parameters. For
> example, given a function test() defined like this:
>   >>> def test(a, b):
>   ...  print a, b
>
> you can call it with ordinary named arguments:
>   >>> test(a='foo', b='bar')
> foo bar
>
> Or you can pass it a dictionary with the named arguments, using extended
calling syntax:
>   >>> d= {'a':'foo', 'b':'bar'}
>   >>> test(**d)
> foo bar
>
>
> Inside the function, if you have a **kwds parameter, it will receive a
dict containing any keyword
> arguments not explicitly declared. This allows you to pass keyword
parameters that you don't
> anticipate when the function is defined. For example,
>
>   >>> def test2(a, **kwds):
>   ...   print a
>   ...   for k,v in kwds.items():
>   ... print k,v
>
>   >>> test2(1) # No keywords
> 1
>   >>> test2(a=1) # a is a declared parameter so kwds is empty
> 1
>   >>> test2(1, b=2, c=3) # b and c are passed in kwds
> 1
> c 3
> b 2
>
> Kent
>
> > individually to differentnoofvars
> > differentnoofvars(a)
> >
> >
> >
> >>>Hey, could you give an example?
> >>>Thanks,
> >>>Jacob
> >>>
> >>>
> apply() is deprecated; it has been replaced by 'extended
> >>>
> >>>call syntax'.
> >>>Instead of
> >>>
>    apply(fn, args, kwds)
> you can now write
>    fn(*args, **kwds)
> 
> Kent
> >>
> >>Here is a quick example I came up with:
> >>
> >>
> >def spam(*args, **kwargs):
> >>
> >>... print "Here are the args you supplied:"
> >>... for item in args:
> >>... print item
> >>... print
> >>... print "Here are the kwargs you supplied:"
> >>... for key,value in kwargs.items():
> >>... print key, '=', value
> >>...
> >>
> >spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> >>
> >>Here are the args you supplied:
> >>1
> >>a
> >>eggs
> >>
> >>Here are the kwargs you supplied:
> >>a = 2
> >>p = 1
> >>s = 0
> >>m = 3
> >>
> >>In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> >>the sequence args (not sure if it is a list or tuple).  The key/value
> >>pairs are bundled into the dictionary kwargs.  The arguments have to be
> >>given in the right order though:
> >>
> >>
> >spam(t=1, b=1, 'this', 'will', 'fail')
> >>
> >>Traceback (SyntaxError: non-keyword arg after keyword arg
> >>
> >>HTH!
> >>
> >>Christian
> >>http://www.dowski.com
> >>
> >>
> >>
> >>
> >
> >
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Thank you!
Wait, though.
How do I do this?
def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
**kwds?
Call it what you like, it's an ordinary function parameter. kwds is commonly used but you can use 
kwargs.
print kwargs
another(kwargs)
Should be another(**kwargs). If you call another(kwargs) then kwargs will be an ordinary parameter 
of another and another would be defined as
def another(kwargs):
  ...

def another(**kwargs):
for x,y in kwagrs.items():
print "%s = %s" % (x,y)
a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
Should be a dict, the **kwds parameter is a dict mapping keywords to values
a = {'a':2, 'f':3, 't':[1,2,3]}
There really are two different and complementary things going on here, at the point of call and at 
the point of function definition.

At the point of call, you can pass a dictionary instead of using explicit, named parameters. For 
example, given a function test() defined like this:
 >>> def test(a, b):
 ...  print a, b

you can call it with ordinary named arguments:
 >>> test(a='foo', b='bar')
foo bar
Or you can pass it a dictionary with the named arguments, using extended 
calling syntax:
 >>> d= {'a':'foo', 'b':'bar'}
 >>> test(**d)
foo bar
Inside the function, if you have a **kwds parameter, it will receive a dict containing any keyword 
arguments not explicitly declared. This allows you to pass keyword parameters that you don't 
anticipate when the function is defined. For example,

 >>> def test2(a, **kwds):
 ...   print a
 ...   for k,v in kwds.items():
 ... print k,v
 >>> test2(1)  # No keywords
1
 >>> test2(a=1)# a is a declared parameter so kwds is empty
1
 >>> test2(1, b=2, c=3) # b and c are passed in kwds
1
c 3
b 2
Kent
individually to differentnoofvars
differentnoofvars(a)

Hey, could you give an example?
Thanks,
Jacob

apply() is deprecated; it has been replaced by 'extended
call syntax'.
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
Here is a quick example I came up with:

def spam(*args, **kwargs):
... print "Here are the args you supplied:"
... for item in args:
... print item
... print
... print "Here are the kwargs you supplied:"
... for key,value in kwargs.items():
... print key, '=', value
...
spam(1,'a','eggs',s=0, p=1, a=2, m=3)
Here are the args you supplied:
1
a
eggs
Here are the kwargs you supplied:
a = 2
p = 1
s = 0
m = 3
In the case of the spam() function, 1, 'a', and 'eggs' are all put into
the sequence args (not sure if it is a list or tuple).  The key/value
pairs are bundled into the dictionary kwargs.  The arguments have to be
given in the right order though:

spam(t=1, b=1, 'this', 'will', 'fail')
Traceback (SyntaxError: non-keyword arg after keyword arg
HTH!
Christian
http://www.dowski.com



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Sorry about that last message. Kent just posted and answered my question
with his example.
Thank you all!

Jacob

> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> > Sent: Friday, December 17, 2004 3:54 PM
> > To: Kent Johnson
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: [Tutor] "TypeError: 'int' object is not callable"??
> >
> > Hey, could you give an example?
> > Thanks,
> > Jacob
> >
> > >
> > > apply() is deprecated; it has been replaced by 'extended
> > call syntax'.
> > Instead of
> > >apply(fn, args, kwds)
> > > you can now write
> > >fn(*args, **kwds)
> > >
> > > Kent
>
> Here is a quick example I came up with:
>
> >>> def spam(*args, **kwargs):
> ... print "Here are the args you supplied:"
> ... for item in args:
> ... print item
> ... print
> ... print "Here are the kwargs you supplied:"
> ... for key,value in kwargs.items():
> ... print key, '=', value
> ...
> >>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> Here are the args you supplied:
> 1
> a
> eggs
>
> Here are the kwargs you supplied:
> a = 2
> p = 1
> s = 0
> m = 3
>
> In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> the sequence args (not sure if it is a list or tuple).  The key/value
> pairs are bundled into the dictionary kwargs.  The arguments have to be
> given in the right order though:
>
> >>> spam(t=1, b=1, 'this', 'will', 'fail')
> Traceback (SyntaxError: non-keyword arg after keyword arg
>
> HTH!
>
> Christian
> http://www.dowski.com
>
>
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Thank you!

Wait, though.

How do I do this?

def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
**kwds?
print kwargs
another(kwargs)

def another(**kwargs):
for x,y in kwagrs.items():
print "%s = %s" % (x,y)

a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
individually to differentnoofvars
differentnoofvars(a)


> > Hey, could you give an example?
> > Thanks,
> > Jacob
> >
> > >
> > > apply() is deprecated; it has been replaced by 'extended
> > call syntax'.
> > Instead of
> > >apply(fn, args, kwds)
> > > you can now write
> > >fn(*args, **kwds)
> > >
> > > Kent
>
> Here is a quick example I came up with:
>
> >>> def spam(*args, **kwargs):
> ... print "Here are the args you supplied:"
> ... for item in args:
> ... print item
> ... print
> ... print "Here are the kwargs you supplied:"
> ... for key,value in kwargs.items():
> ... print key, '=', value
> ...
> >>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> Here are the args you supplied:
> 1
> a
> eggs
>
> Here are the kwargs you supplied:
> a = 2
> p = 1
> s = 0
> m = 3
>
> In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> the sequence args (not sure if it is a list or tuple).  The key/value
> pairs are bundled into the dictionary kwargs.  The arguments have to be
> given in the right order though:
>
> >>> spam(t=1, b=1, 'this', 'will', 'fail')
> Traceback (SyntaxError: non-keyword arg after keyword arg
>
> HTH!
>
> Christian
> http://www.dowski.com
>
>
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Hey, could you give an example?
I'll try...
Here is range with three explicit arguments
 >>> range(1, 10, 2)
[1, 3, 5, 7, 9]
Here is range with the arguments supplied in a list; it does the same thing
 >>> args = [1, 10, 2]
 >>> range(*args)
[1, 3, 5, 7, 9]
Here is an example with zip(). zip() normally takes multiple arguments, this makes it use elements 
of a single list:
 >>> l=[ [1,2], [3,4], [5,6] ]
 >>> zip(*l)
[(1, 3, 5), (2, 4, 6)]

Kent
Thanks,
Jacob

apply() is deprecated; it has been replaced by 'extended call syntax'.
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> Sent: Friday, December 17, 2004 3:54 PM
> To: Kent Johnson
> Cc: [EMAIL PROTECTED]
> Subject: Re: [Tutor] "TypeError: 'int' object is not callable"??
> 
> Hey, could you give an example?
> Thanks,
> Jacob
> 
> >
> > apply() is deprecated; it has been replaced by 'extended 
> call syntax'.
> Instead of
> >apply(fn, args, kwds)
> > you can now write
> >fn(*args, **kwds)
> >
> > Kent

Here is a quick example I came up with:

>>> def spam(*args, **kwargs):
... print "Here are the args you supplied:"
... for item in args:
... print item
... print
... print "Here are the kwargs you supplied:"
... for key,value in kwargs.items():
... print key, '=', value
... 
>>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
Here are the args you supplied:
1
a
eggs

Here are the kwargs you supplied:
a = 2
p = 1
s = 0
m = 3

In the case of the spam() function, 1, 'a', and 'eggs' are all put into
the sequence args (not sure if it is a list or tuple).  The key/value
pairs are bundled into the dictionary kwargs.  The arguments have to be
given in the right order though:

>>> spam(t=1, b=1, 'this', 'will', 'fail')
Traceback (SyntaxError: non-keyword arg after keyword arg

HTH!

Christian
http://www.dowski.com


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Hey, could you give an example?
Thanks,
Jacob

>
> apply() is deprecated; it has been replaced by 'extended call syntax'.
Instead of
>apply(fn, args, kwds)
> you can now write
>fn(*args, **kwds)
>
> Kent
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Ha! That's what I was looking for! The builtin apply function! The only way
I could send the *args to the function was through a list, and function
calls see a list as one argument. The apply argument doesn't! Thanks Bob.
apply() is deprecated; it has been replaced by 'extended call syntax'. 
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-16 Thread Jacob S.
Ha! That's what I was looking for! The builtin apply function! The only way
I could send the *args to the function was through a list, and function
calls see a list as one argument. The apply argument doesn't! Thanks Bob.

Jacob Schmidt

> At 12:39 PM 12/8/2004, Bob Gailer wrote:
> >At 11:27 AM 12/8/2004, Dick Moores wrote:
> >>My thanks to both Max and Kent. So Python tries, and fails, to see 2()
as
> >>a function!
> >>
> >>I also got some help from 
> >
> >Note that SOME languages use () for call. There are other call
constructs,
> >such as:
> >
> >DO function WITH parameters (FoxPro, similar in COBOL)
> >
> >function parameter   or   parameter1 function parameter2 (APL)
>
> I should add the Python builtin function apply: apply(function,
parameters...)
>
> Bob Gailer
> [EMAIL PROTECTED]
> 303 442 2625 home
> 720 938 2625 cell
>
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Alan Gauld
> Note that SOME languages use () for call. There are other call
constructs,
> such as:
>
> DO function WITH parameters (FoxPro, similar in COBOL)
>
> function parameter   or   parameter1 function parameter2 (APL)

And in Smalltalk:

object message: parameter1 : parameter2 :
parameter3

Or as an example of a message and one descriptor.

myArray put: foo at: 5

The array method is known as   "put:at:"

No parens to be seen (they have a completely different meaning in
Smalltalk)

Alan G.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Bob Gailer
At 12:39 PM 12/8/2004, Bob Gailer wrote:
At 11:27 AM 12/8/2004, Dick Moores wrote:
My thanks to both Max and Kent. So Python tries, and fails, to see 2() as 
a function!

I also got some help from 
Note that SOME languages use () for call. There are other call constructs, 
such as:

DO function WITH parameters (FoxPro, similar in COBOL)
function parameter   or   parameter1 function parameter2 (APL)
I should add the Python builtin function apply: apply(function, 
parameters...)
Bob Gailer
[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Bob Gailer
At 11:27 AM 12/8/2004, Dick Moores wrote:
My thanks to both Max and Kent. So Python tries, and fails, to see 2() as 
a function!

I also got some help from 
Note that SOME languages use () for call. There are other call constructs, 
such as:

DO function WITH parameters (FoxPro, similar in COBOL)
function parameter   or   parameter1 function parameter2 (APL)
Bob Gailer
[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Dick Moores
My thanks to both Max and Kent. So Python tries, and fails, to see 2() as 
a function!

I also got some help from 
Dick  

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Kent Johnson
A callable is something that can be called with functional notation. It can be a function, a class, 
or in some cases a class instance. In general, any object that has a __call__() special method is 
callable. The callable() built-in tells you if an object is callable, though you can also just try 
it. For example,

the built-in len is callable and has a __call__ attribute:
>>> callable(len)
True
>>> dir(len)
['__call__', ... ]
1 is not callable and does not have a __call__ attribute:
>>> callable(1)
False
>>> dir(1)
[ ]
As you discovered, trying to call 1 as a function doesn't work:
>>> 1()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: 'int' object is not callable
A user-defined function is callable and has a __call__ attribute:
>>> def f(): pass
...
>>> callable(f)
True
>>> dir(f)
['__call__', ... ]
>>>
A class is callable (you call it to create an instance):
>>> class C:
...   pass
...
>>> callable(C)
True
Instances of a class, in general, are not callable:
>>> c=C()
>>> callable(c)
False
You can make a class whose instances are callable by defining a __call__ method on the class. This 
allows you to make a class whose instances behave like functions, which is sometimes handy. (This 
behaviour is built-in to Python - __call__() is called a special method. There are many special 
methods that let you customize the behaviour of a class.)

>>> class D:
...   def __call__(self, x):
... print 'x =', x
...
>>> d=D()  # Calling the class creates an instance
>>> callable(d)
True
>>> d(3)  # Calling the instance ends up in the __call__() method of the class
x = 3
Kent
Dick Moores wrote:
I got this error msg for this line of code:
n = -(2(a**3.0)/27.0 - a*b/3.0 + c)
(where a = 1, b = 2, c = 3)
And was baffled until I realized the line should be
n = -(2*(a**3.0)/27.0 - a*b/3.0 + c)
But I still don't understand what "callable" means. Can someone help?
Thanks,
Dick Moores
[EMAIL PROTECTED]
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-08 Thread Max Noel
On Dec 8, 2004, at 17:01, Dick Moores wrote:
I got this error msg for this line of code:
n = -(2(a**3.0)/27.0 - a*b/3.0 + c)
(where a = 1, b = 2, c = 3)
And was baffled until I realized the line should be
n = -(2*(a**3.0)/27.0 - a*b/3.0 + c)
But I still don't understand what "callable" means. Can someone help?
	Basically, when you try to execute your first line, the program tries 
to call the function 2 on the argument (a**3.0). Which of course fails, 
because 2 is an int, not a "callable" object (function, method, lambda 
or class). Hence "'int' object is not callable".

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor