Reputation: 309
I'm trying to clean up strings containing percent symbols. What I intend do is replace each %
with %%
!
When I use my_string.replace("%", "%%")
, it works out fine in Python 3.
However, when I do the same in Python 2.7 and print the result (using the future print function), it simply prints the original string. I guess this happens, because %% is commonly used to escape the percent symbol in strings?
What would be a viable workaround for Python 2.7? I'm parsing FFmpeg commands, and single percent symbols are forbidden, since FFmpeg uses %d
to indentify number sequences in filenames of image sequences.
Thanks.
Upvotes: 0
Views: 816
Reputation: 96
Using python 2.7 this is an example to replace % by %%:
import string
str = "replace % "
str = string.replace(str, "%","%%")
print "Result:",str
The result is:
Result: replace %%
Upvotes: 1