[Tutor] Callable? Whats callable?

Bruce Sass bsass@freenet.edmonton.ab.ca
Sun, 26 Aug 2001 14:10:59 -0600 (MDT)


On Sun, 26 Aug 2001, epoch7 wrote:

> alright. so i fixed the error in y. originally i started putting in the
> read()s and stuff to be able to fix an error/find a workaround.
> i was getting, here's how i got that error:
>
> 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()
> text = re.compile('url=(\w*)&', re.IGNORECASE)

...ok...

> y = text.findall(x)
> y.write(text)

...but that bit ain't right.

----- re.findall() example -----
>>> import re
>>> instring = """
... Just some text, any text,
... the more text the better...
... It needn't be good text.
... """
>>> target = re.compile('text')
>>> print re.findall(target,instring)
['text', 'text', 'text', 'text']
----- end example -----

Maybe what you want is...

import string
out_file.write(string.join(re.findall(text,x),"\n"))

...or, if you prefer...

y = re.findall(text,x)
y = string.join(y,'\n')
out_file.write(y)

> in_file.close()
> out_file.close()
>
> and here's the error
>
> Traceback (most recent call last):
>   File "F:\Python21\reusage.py", line 11, in ?
>     y.write(text)
> AttributeError: write
>
> im sure you all know what im doing wrong...

...not playing with the interpreter enough.  ;-)


- Bruce