如果我在字符串中有路径,例如:
'Documents/Programming/Python scripts/'
我想在\
Python
这样看起来像:
Documents/Programming/Python\ scripts/
我该怎么做?
答案 0 :(得分:0)
您可以使用replace
方法:
>>> s = 'Documents/Programming/Python scripts/'
>>> s = s.replace(' ', '\ ')
>>> print s
Documents/Programming/Python\ scripts/