Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78719
| From | Shiva <shivaji_tn@yahoo.com> |
|---|---|
| Subject | Re: re search through a text Vs line |
| Date | 2014-10-05 17:08 +0000 |
| References | <loom.20141005T113100-941@post.gmane.org> <m0rbif$bgu$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14614.1412528943.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: re search through a text Vs line Shiva <shivaji_tn@yahoo.com> - 2014-10-05 17:08 +0000
csiph-web