Having trouble using %s with re.sub

test = '/my/word/whats/wrong'
re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)

return is /my/@0/whats/wrong

however if I cast a value with letters as opposed to numbers

re.sub('(/)word(/)', r'\1\%s\2'%'gosh', test)

return is /my/gosh/whats/wrong


Any help would be good. I've tried passing the value as an int, or recasting that value as something else, passing it as a raw string, removing the r and just double escaping the groups.

Brandon L. Harris

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

Reply via email to