basic question: target assignment in for loop

Mike C. Fletcher mcfletch at rogers.com
Mon Feb 24 02:42:00 EST 2003


html = [
    re.sub("regexString", functionReturningString, line)
    for line in htmlFile
]

Might be somewhat more elegant feeling?

HTH,
Mike

Kawaldeep Grewal wrote:
...

>html = htmlFile.readlines()
>i = 0
>while i < len(html):
>        html[i] = re.sub("regexString", functionReturningString, html[i])
>        i = i + 1
>
>this code is decidedly not elegant, and looks very C-ish. As I'm new to 
>python, can anyone tell me whether I'm just confused or that this is the 
>way to do things?
>  
>
...

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list