Reputation: 3008
time = re.search(r'\d\d:\d\d:\d\d' , f.read().decode('utf-16'))
print time.group()
and
number = re.search(r'[TEL:+]\d+\n', f.read().decode('utf-16'))
print number.group()
both code works fine individually , but when I try to run in single script like this :
number = re.search(r'[TEL:+]\d+\n', f.read().decode('utf-16'))
print number.group()
time = re.search(r'\d\d:\d\d:\d\d' , f.read().decode('utf-16'))
print time.group()
second pattern didn't worked .
print time.group()
AttributeError: 'NoneType' object has no attribute 'group'
Any idea what I am missing here ?
Upvotes: 0
Views: 25
Reputation: 32207
This is because the first read()
consumes the whole file.
You should reset the pointer after the first read()
as follows:
number = re.search(r'[TEL:+]\d+\n', f.read().decode('utf-16'))
print number.group()
f.seek(0,0)
time = re.search(r'\d\d:\d\d:\d\d' , f.read().decode('utf-16'))
print time.group()
Upvotes: 2