Relative paths in Python

前端 未结 15 1491
陌清茗
陌清茗 2020-11-22 07:39

I\'m building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don\'t, however, have the absolute path

15条回答
  •  终归单人心
    2020-11-22 08:04

    I think to work with all systems use "ntpath" instead of "os.path". Today, it works well with Windows, Linux and Mac OSX.

    import ntpath
    import os
    dirname = ntpath.dirname(__file__)
    filename = os.path.join(dirname, 'relative/path/to/file/you/want')
    

提交回复
热议问题