Using re.sub with %s
Brandon Harris
brandon.harris at reelfx.com
Wed Aug 18 13:37:11 EDT 2010
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
More information about the Python-list
mailing list