[Tutor] Re: Callable? Whats callable?
Sun, 26 Aug 2001 16:32:16 -0400
"epoch7" <firstname.lastname@example.org> wrote, in part:
> y =3D """%s""" (x)
A 'callable' thing is a section of program code that can be used
(called) by another program to do some work for the callER.
Let me first duplicate the message you saw. I can tell that your
name 'x' points to a string that you read from a file. I'll just make 'x'
point to an arbitrary string, to avoid the carry-on of reading from a
>>> x = 'Fourty-two'
>>> y = """%s""" (x)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: object is not callable: '%s'
In this case, when Python sees '(x)' in your line of code it
concludes that the object preceding it must be 'callable', ie, a
function, say. It examines that object, which happens to be '%s',
compares it with the kinds of objects that can be called (or used if
you will) by other programs, finds that it's a string, however, and
makes the rude complaint that you see.
So, what to do, eh?
My guess is that you want to convert the object to which 'x' points
to a string and then make 'y' point to the converted object. If I have
guessed correctly then you need to write,
>>> y = "%s" % (x)
rather than what you did.
Or, IOW, just insert the '%' operator in your statement. Now when
Python examines this statement it understands that you want to
convert the content of 'x' using the specification '%s' and it
complaineth no more.
Incidentally I haven't examined any of the rest of your script. I
assume that if you wanted us to comment about that you would
have asked us. :o)
Bill Bell, Software Developer