Relative paths in Python

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

    I'm not sure if this applies to some of the older versions, but I believe Python 3.3 has native relative path support.

    For example the following code should create a text file in the same folder as the python script:

    open("text_file_name.txt", "w+t")
    

    (note that there shouldn't be a forward or backslash at the beginning if it's a relative path)

提交回复
热议问题