Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How can leading edge spaces be stripped for each line in the string variable `interface_info` before parsing?

import re     
interface_info = '''  
    phy#3  
            Interface wlan1-cabin-2  
                    ifindex 37  
                    wdev 0x300000003  
                    addr 06:53:1a:4e:07:02  
                    ssid SSIDTEST3  
                    type AP  
                    channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz  
            Interface wlan1-cabin-1  
                    ifindex 36  
                    wdev 0x300000002  
                    addr 06:53:1a:4e:07:01  
                    ssid SSIDTEST2  
                    type AP  
                    channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz  
            Interface wlan1  
                    ifindex 7  
                    wdev 0x300000001  
                    addr 06:53:1a:4e:07:00  
                    ssid SSID1  
                    type AP  
                    channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz  
    phy#2  
            Interface wlan0  
                    ifindex 6  
                    wdev 0x200000001  
                    addr 00:30:1a:4e:07:ac  
                    type managed  
    '''  
    stripped = interface_info.lstrip(' \t\n\r')  
    ssid_regex = re.compile('Interface wlan1-cabin-2+((.*\n){6})')  
    ssid_extract = re.search(ssid_regex, stripped)  
    interface_split = re.split(r'\n', ssid_extract.group(0))  
    ssid = str(interface_split[4]).strip(' ssid ')  

    print(stripped)
    print (ssid_extract)
    print str(interface_split)
    print (ssid)

Output:

<b> 
<_sre.SRE_Match object at 0x7fb1665e2250>  
['Interface wlan1-cabin-2', '                ifindex 37', '                wdev 0x300000003', '                addr 06:53:1a:4e:07:02', '                ssid SSIDTEST3', '                type AP', '']  
SSIDTEST3`
</b>

In the output of the above code, note each string in the list has leading edge spaces. I am trying to trip/strip those spaces before the strings end up in the list.

Comments