Relative paths in Python

前端 未结 15 1669
陌清茗
陌清茗 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:57

    you need os.path.realpath (sample below adds the parent directory to your path)

    import sys,os
    sys.path.append(os.path.realpath('..'))
    

提交回复
热议问题