[Tutor] Callable? Whats callable?

alan.gauld@bt.com alan.gauld@bt.com
Sun, 26 Aug 2001 16:45:00 +0100


------_=_NextPart_001_01C12E46.1084C690
Content-type: text/plain; charset="ISO-8859-1"

I'm new to programming, python, and even this list!  

Looks like your doing all the right things so far, welcome :-)

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()
 

OK down to here, you now have the contents of file1 stored as 
a long string in x...

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

You meant to do:
 
y="%s" % x
 
The triple quotes aren't needed and the parens are only needed 
if theres several items to insert into the format string.
 
The reason you got the callable error was you had parens after the string so
 
But why are you copying the string in x into y? I can't see the 
reason for doing it.

 
 
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


------_=_NextPart_001_01C12E46.1084C690
Content-type: text/html; charset="ISO-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial size=2>I'm new to programming, python, and even this 
  list!&nbsp;<SPAN class=170524315-26082001><FONT color=#0000ff 
  face="Courier New">&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>Looks like your doing all the right things so far, 
welcome :-)</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial size=2>import re<BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>file1 = raw_input("Name of file to convert: 
  ")<BR>file2 = raw_input("Name of file to output to: ")<BR>in_file = 
  open(file1, "r")<BR>out_file = open(file2, "w")<BR>x&nbsp;= 
  in_file.read()<BR><SPAN class=170524315-26082001><FONT color=#0000ff 
  face="Courier New">&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>OK down to here, you now have the contents of file1 
stored as </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>a long string in x...</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial size=2><SPAN 
  class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT size=2><FONT face=Arial><SPAN 
  class=170524315-26082001>&nbsp;</SPAN>y&nbsp;= """%s""" (x)<SPAN 
  class=170524315-26082001><FONT color=#0000ff 
  face="Courier New">&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT size=2><FONT face=Arial><SPAN 
  class=170524315-26082001></SPAN></FONT></FONT>&nbsp;</DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>You meant to do:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT><FONT color=#0000ff face="Courier New" 
size=2><SPAN class=170524315-26082001>y="%s" % x</SPAN></FONT><FONT 
color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>The triple quotes aren't needed and the parens are only 
needed </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT><FONT color=#0000ff face="Courier New" 
size=2><SPAN class=170524315-26082001>if theres several items to insert into the 
format string.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>The reason you got the callable error was you had 
parens after the string so</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>But why are you copying the string in x into y? I can't 
see the </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
class=170524315-26082001>reason for doing it.</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
  class=170524315-26082001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT size=2><FONT face=Arial><SPAN 
  class=170524315-26082001>&nbsp;</SPAN><BR>text = re.compile('url=(\w*)&amp;', 
  re.IGNORECASE)<BR>text.findall(y)<BR>in_file.close()<BR>out_file.close()</FONT></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>thats it. it's the latest incantation of this 
  program, ive been trying really hard to get this workin'.</FONT></DIV>
  <DIV><FONT face=Arial size=2>here's the error i get: </FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Traceback (most recent call last):<BR>&nbsp; File 
  "F:\Python21\reusage.py", line 10, in ?<BR>&nbsp;&nbsp;&nbsp;&nbsp;y = 
  """%s""" (x)<BR>TypeError: object of type 'string' is not 
callable</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>And for those of you just wondering what&nbsp;im 
  trying to do, its supposed to search out for strings of text</FONT></DIV>
  <DIV><FONT face=Arial size=2>between to strings("url=" and "&amp;").&nbsp; and 
  then output the list of strings to a file.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Seems simple enough but I guess i really bit off 
  more than i could chew for my first real program! :(</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>will</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C12E46.1084C690--