2015-11-03 190 views
1

文件路径如何获得 '路径/到/文件/'越来越以 '/'

这是缺少最后的 '/'

In [2]: os.path.join('path', 'to', 'file') 
Out[2]: 'path/to/file' 

这并没有帮助:

In [3]: os.path.join('path', 'to', 'file', '/') 
Out[3]: '/' 
+0

我很好奇:你为什么要在文件名上做最后的斜线? –

+0

我连接了2个os.path.joins –

+0

如果你连接两个路径连接,那么你的代码应该看起来像'os.path.join('path','to','file'),os .path.join('second','path'))',一切都会好的。 – Matthias

回答

2

只需自行新增:os.path.join('path', 'to', 'file') + os.path.sep

1

有你试过:os.path.join( '路径', '到', '文件' + os.sep)