re search through a text Vs line

Shiva shivaji_tn at yahoo.com
Sun Oct 5 05:36:53 EDT 2014


Hi,

I am doing a regular expression search for a year through a file.

  fileextract = open(fullfilename,'r')
  line = fileextract.read()
  texts = re.search(r'1\d\d\d', line)
  print(texts.group())

The above works.

However if I do:
     fileextract = open(fullfilename,'r')
     line = fileextract.readlines()

     for l in line:
        texts = re.search(r'1\d\d\d', line)
     print(texts.group())


None is returned. Why is it not iterating through each line of the file and
doing a search? - It seems to return none.

Thanks,
Shiva




More information about the Python-list mailing list