[Tutor] re module help

Ganesh Kumar bugcy013 at gmail.com
Mon Jan 9 10:17:46 CET 2012


Hi Gurus,

I have created regular expression with os modules, I have created file
sdptool to match the regular expression pattern, will print the result.
I want without creating file how to get required output, I tried but i
didn't get output correctly, over stream.

#! /usr/bin/python
import os,re

def scan():

    cmd = "sdptool -i hci0 search OPUSH > sdptool"
    fp = os.popen(cmd)

    results = []
    l = open("sdptool").read()


    pattern = r"^Searching for OPUSH on (\w\w(:\w\w)+).*?Channel: (\d+)"
    r = re.compile(pattern, flags=re.MULTILINE|re.DOTALL)
    while True:
        for match in r.finditer(l):
            g  = match.groups()

            results.append((g[0],'phone',g[2]))
            return results

## output [('00:15:83:3D:0A:57', 'phone', '1')]


http://dpaste.com/684335/
please guide me. with out file creating, to archive required output.


Did I learn something today? If not, I wasted it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120109/e92b3898/attachment.html>


More information about the Tutor mailing list