On 2016-09-21 19:35, Ganesh Pal wrote:
Thanks Steve  for the clues , quickly tried  out # Version 1 doesn't seen
to work.


for line in hostname:
...     regex = r'(.*) is array with id {}'.format(devid)
...     mo = re.search(regex, line)
...     print line, regex, mo
...     if mo is not None:
...         print mo.group(1)
...
RX-145-1 is array id 1 (.*) is array with id 3 None
RX-145-2 is array id 2 (.*) is array with id 3 None
RX-145-3 is array id 3 (.*) is array with id 3 None
hostname
['RX-145-1 is array id 1', 'RX-145-2 is array id 2', 'RX-145-3 is array id
3']
type(devid)
<type 'int'>
devid
3
---------------------------------------------------------------------------------------------------
devid = '3'
for line in hostname:
...     regex = r'(.*) is array with id {}'.format(devid)
...     mo = re.search(regex, line)
...     print line, regex, mo
...     if mo is not None:
...        print mo.group(1)
...
RX-145-1 is array id 1 (.*) is array with id 3 None
RX-145-2 is array id 2 (.*) is array with id 3 None
RX-145-3 is array id 3 (.*) is array with id 3 None
type(devid)
<type 'str'>
----------------------------------------------------------------------------------------------
for line in hostname:
...     regex = r'(.*) is array with id %d' % (devid)
...     mo = re.search(regex, line)
...     print line, regex, mo
...     if mo is not None:
...        print mo.group(1)
...
RX-145-1 is array id 1 (.*) is array with id 3 None
RX-145-2 is array id 2 (.*) is array with id 3 None
RX-145-3 is array id 3 (.*) is array with id 3 None
---------------------------------------------------------------------------------------------------

Looks like Iam missing something ?

[snip]
The lines have "array id", but the regex has "array with id".

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to