[Tutor] Avoiding repetetive pattern match in re module

bob bgailer at alum.rpi.edu
Thu Jan 5 19:15:14 CET 2006


At 02:41 AM 1/5/2006, Intercodes wrote:
>Hello everyone,
>
>     Iam new to this mailing list as well as python(uptime-3 
> weeks).Today I learnt about RE from 
> <http://www.amk.ca/python/howto/regex/%22RE%27s>http://www.amk.ca/python/howto/regex/.This 
> one was really helpful. I started working out with few examples on 
> my own. The first one was to collect all the HTML tags used in an 
> HTML file. I wrote this code.
>
>------------------------------
>import re
>file1=open(raw_input("\nEnter The path of the HTML file: "),"r")
>ans=""
>while 1:
>     data=file1.readline()
>     if data=="":
>         break
>     ans=ans+data

Consider a shorter way to grab the entire file:
ans = open(raw_input("\nEnter The path of the HTML file: "),"r").read()

[snip] 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060105/ac872a37/attachment.htm 


More information about the Tutor mailing list