How to create a file one directory up?

后端 未结 3 1476
一生所求
一生所求 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:17

    Depends whether you are working in a unix or windows environment.

    On windows:

    ..\foo.txt
    

    On unix like OS:

    ../foo.txt
    

    you need to make sure the os sets the current path correctly when your application launches. Take the appropriate path and simply create a file there.

提交回复
热议问题