re search through a text Vs line

Shiva shivaji_tn at yahoo.com
Sun Oct 5 13:08:49 EDT 2014


OK,
Hi Dave,

I modified it as below and it works....(If there is a way to make this more
efficient please let me know)

By the way I am using Python 3.4

import sys
import re


def extract_names(filename):

  path = '/home/LearnPython/exercises/'
  fullfilename = path+filename
  print('fullfilename: ',fullfilename)

  fileextract = open(fullfilename,'r')
  #line = fileextract.readlines()
  #print(line)
  for l in fileextract:
    #print(l)
    texts = re.search(r'\d\d\d\d', l)
    if texts:
      print(texts.group())


    #print(texts.group())

  #return texts.group()
  fileextract.close()



extract_names('NOTICE.txt')

Thanks,
Shiva




More information about the Python-list mailing list