How do I use '~' (tilde) in the context of paths?

前端 未结 3 1999
不知归路
不知归路 2020-12-08 00:38

I\'m a web application development noob. I have a function that opens a file and reads it. Unfortunately, the directory structures between the test and production servers di

3条回答
  •  情深已故
    2020-12-08 00:46

    If you are using pathlib for filenames then you can use on both Windows and Linux (I came here for a windows answer):

    python from pathlib import Path p = Path('~').expanduser() print(p)

提交回复
热议问题