[Tutor] Callable? Whats callable?

Rob Andrews rob@jam.rr.com
Sun, 26 Aug 2001 10:28:53 -0500


> epoch7 wrote:
> 
> I'm new to programming, python, and even this list! So hopefullt
> someone could give me a hand with my first program.
> 
> import re
> file1 = raw_input("Name of file to convert: ")
> file2 = raw_input("Name of file to output to: ")
> in_file = open(file1, "r")
> out_file = open(file2, "w")
> x = in_file.read()
> y = """%s""" (x)
> text = re.compile('url=(\w*)&', re.IGNORECASE)
> text.findall(y)
> in_file.close()
> out_file.close()
> 
> thats it. it's the latest incantation of this program, ive been trying
> really hard to get this workin'.
> here's the error i get:
> 
> Traceback (most recent call last):
>   File "F:\Python21\reusage.py", line 10, in ?
>     y = """%s""" (x)
> TypeError: object of type 'string' is not callable
> 
> And for those of you just wondering what im trying to do, its supposed
> to search out for strings of text
> between to strings("url=" and "&").  and then output the list of
> strings to a file.
> 
> Seems simple enough but I guess i really bit off more than i could
> chew for my first real program! :(
> 
> will

I saved your source as somedudesfile.py and ran it from within IDLE.
Here's what happened:

Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import somedudesfile
Name of file to convert: C:\someletters.txt
Name of file to output to: C:\someletters2.txt
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    import somedudesfile
  File "E:\Python21\somedudesfile.py", line 8, in ?
    y = """%s""" (x)
TypeError: object of type 'string' is not callable

Then I went into the source file and changed this line:

y = """%s""" (x)

to this line:

y = """%s""" % (x)

After saving the file, it reloads without error.

>>> import somedudesfile
>>> reload(somedudesfile)
Name of file to convert: C:\someletters.txt
Name of file to output to: C:\someletters2.txt
<module 'somedudesfile' from 'E:\Python21\somedudesfile.py'>
>>> 

You were almost there, it looks like. And your first program seems to be
more impressive than my first Python program:

print 'hello world'

Rob
-- 
A {} is a terrible thing to waste.
Useless Python!
http://www.lowerstandard.com/python