Reputation: 165
I am communicating to serial ports via python. I passed an AT command to list the phone directory. Now I need to fetch the phone number I received. How do I fetch that particular number via python.
+CMGR: "REC READ","+911234567890",,"13/05/31,10:00:14+22"
Upvotes: 0
Views: 182
Reputation: 142136
If the number is always the nth field, then:
s = '+CMGR: "REC READ","+911234567890",,"13/05/31,10:00:14+22"'
import csv
print next(csv.reader([s]))[1]
# +911234567890
Upvotes: 1
Reputation: 250921
something like this?
>>> import re
>>> strs = '+CMGR: "REC READ","+911234567890",,"13/05/31,10:00:14+22'
>>> re.search(r'"(\+91\d+)"', strs).group(1)
'+911234567890'
>>>
Upvotes: 1