Relative paths in Python

前端 未结 15 1654
陌清茗
陌清茗 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 07:56

    An alternative which works for me:

    this_dir = os.path.dirname(__file__) 
    filename = os.path.realpath("{0}/relative/file.path".format(this_dir))
    

提交回复
热议问题