Path in Variable with r'

坚强是说给别人听的谎言 提交于 2019-12-13 02:33:44

问题


I want to replace this: path = r'C:/Folder with this: path = r'variable

Where variable is defined elsewhere.

In not sure how to put the variable name after the r'


回答1:


Just use path = variable.

The point of the r'...' notation is for writing raw string literals; it changes the rules for character escaping inside of the quotes. If you're just getting the value from another variable, there's no need for an r since you're not writing a string literal.




回答2:


This should work:

path = r'%s' % variable


来源:https://stackoverflow.com/questions/28313886/path-in-variable-with-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!