以下代码扩展了列表但插入了双反斜杠“\\”。
如何使用一个反斜杠“\”扩展到列表?
x =["env1","env2","env3"]
j=[]
for env in x:
q="\\\\servername\path"+env+"\path"
w="\\\\servername\path"+env+"\path"
j.extend((q,w))
print j # ['\\\\\\\servername\\\pathenv1\\\\path',...]
我尝试将其转换为原始字符串但仍然遇到同样的问题:
x =["env1","env2","env3"]
j=[]
for env in x:
q=r"\servername\path"+env+"\path"
w=r"\\servername\path"+env+"\path"
j.extend((q,w))
print j # [\\\servername\\\path\\\path', '\\\\\\\servername\\\\path\\\path',...]