python 路径拼接

windows和linux路径斜杠不兼容问题

windows
>>> import os
>>> os.getcwd()
'C:\\Program Files (x86)\\python27'
>>> os.path.join(os.getcwd(),"hello")
'C:\\Program Files (x86)\\python27\\hello'
>>> os.path.join(os.getcwd(),"hello","hi")
'C:\\Program Files (x86)\\python27\\hello\\hi'

linux
>>> import os
>>> os.path.join(os.getcwd(),"infra",'CMake.txt')
'/home/dev/vlyu/infra/CMake.txt'

 

 

 

 

 

 

 

 

posted @ 2020-12-23 22:30  anobscureretreat  阅读(567)  评论(0编辑  收藏  举报