for line3 in myips matching too longer matches.

Sayth Renshaw flebber.crue at gmail.com
Wed Jun 26 20:37:03 EDT 2019


Chris Roberts  wrote:
> ###
> CODE:
>            elif line1.rstrip(‘\n’) in line2.strip(‘\n’):
>                for line3 in myips:
>                    print “###”
>                    print “line1 is %s” % line1.rstrip(‘\n’)
>                    print “line2 is %s” % line2.strip(‘\n’)
> ###
> OUTPUT:
> line1 is 10.10.168.2
> line2 is              - address: 10.10.168.27  # myhost
> ###
> 
> I think the problem is here: 
> line1.rstrip(‘\n’) in line2.strip(‘\n’):  
> 
> I want it to
> match only 10.10.168.2 AND 10.10.168.2:
> NOT match 10.10.168.2[0-9]
> 
> If someone out there knows a simple solution. I would love to see it.
> Thanks in advance. 
> crzzy1

Not sure exactly what the input is but a comprehension would do this.

[x for x in input_line.split(' ') if == '10.10.168.2']

Cheers

Sayth




More information about the Python-list mailing list