regex - Python Fabric won't comment beginning of line -


just trying comment out line in text file in python fabric. regex @ sign doesn't have ip1 or ip2 following. pattern searches fine , finds line, except instead of printing "# + line" prints "#@#@bad_ip_here". should :

#*.info;mail.none;stuff.none;cron.none                @bad_ip 

but prints

*.info;mail.none;stuff.none;cron.none                #@#@bad_ip 

it printing commented line twice, fine. don't know wrong or changed. tried forcing insert @ position 0 with

line = line[:0] + "#" + line[0:] 

but didn't work either.

def addcomments():     ip1 = '10.31.xx.xxx'     ip2 = '10.30.xx.xx'     host = env.host_string     conf = open('/home/myuser/verify_yslog_conf/%s/hi.txt' % host, 'r')     f = conf.read()     conf.close()     comment = open('/home/myuser/verify_yslog_conf/%s/hi.txt' % host, 'w')     line in f:         if re.search(r'(@(?!({0}|{1})))'.format(ip1, ip2), line):             line = "#" + line             comment.write(line)          comment.write(line)     comment.close() 

thanks


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -