【发布时间】:2017-11-24 14:21:45
【问题描述】:
我想使用 os.join.path
我试过这些方法
import os
a = 'BIWDB02'
b = 'e$\research'
c = '\\\\'
print c
# \\
Try-1:
x = os.path.join('\\','\\',a,b)
print x
输出:
\BIWDB02\e$
esearch
不知道为什么它会出现在下一行,甚至'r'都不见了。
Try-2 ,3
y = os.path.join('\\\\',a,b)
print y
z= os.path.join(c,a,b)
print z
错误:
IndexError: 字符串索引超出范围
更新:
os.path.join('\\\\\\',a,b)
#\\\BIWDB02\e$\research
使用 6-\\\\ 它给了我 3-\\ 但使用 4-\\ 它又给了我 indexError。
【问题讨论】:
-
\r 是回车符;它告诉您的终端仿真器将光标移动到行首
-
将
b定义为b = r'e$\research',然后执行os.path.join(a,b)。应该够了 -
有关原始字符串文字的更多详细信息,请参阅this question。
-
我已经更新了我的输出:开始时应该是 \\
标签: string python-2.7 path