Create file path from variables

后端 未结 3 1034
忘了有多久
忘了有多久 2020-12-25 10:23

I am looking for some advice as to the best way to generate a file path using variables, currently my code looks similar to the following:

path = /my/root/di         


        
3条回答
  •  借酒劲吻你
    2020-12-25 10:34

    Yes there is such a built-in function: os.path.join.

    >>> import os.path
    >>> os.path.join('/my/root/directory', 'in', 'here')
    '/my/root/directory/in/here'
    

提交回复
热议问题