How to create a file one directory up?

后端 未结 3 1474
一生所求
一生所求 2021-02-07 12:42

How can I create a file in python one directory up, without using the full path?

I would like a way that worked both for windows and linux.

Thanks.

3条回答
  •  一向
    一向 (楼主)
    2021-02-07 13:18

    People don't seem to realize this, but Python is happy to accept forward slash even on Windows. This works fine on all platforms:

    fobj = open("../filename", "w")
    

提交回复
热议问题