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

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Fri Dec 17 23:15:49 CET 2004


> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Jacob S.
> Sent: Friday, December 17, 2004 3:54 PM
> To: Kent Johnson
> Cc: tutor at python.org
> 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




More information about the Tutor mailing list