python 创建路径和路径拼接代码示例

python 判断路径是否存在,不存在就创建该路径de代码

path = 'E:/sub01/肖战'
if not os.path.exists(path):
    os.makedirs(path)
else:
    print('路径已存在')

python 关于路径的拼接问题

path = 'E:/PyEVM-master/PyEVM-master/'
allPath = os.path.join(path,'sub01')
print(allPath)

输出:

E:/PyEVM-master/PyEVM-master/sub01

python 路径拼接也可以用‘+’号实现—相当于字符串的连接

path = 'E:/PyEVM-master/PyEVM-master'
#allPath = path + '/' + 'sub01'
allPath = path +  '/sub01'
print(allPath)

输出:

E:/PyEVM-master/PyEVM-master/sub01

你可能感兴趣的:(python 创建路径和路径拼接代码示例)