Python doesn't find a directory using the home sign ~

后端 未结 2 1783
日久生厌
日久生厌 2020-12-11 08:47

I have created a small Python script to save directories in a side directory, under the current user. I am running on Mac but production is Ubuntu

My problem is the

相关标签:
2条回答
  • 2020-12-11 08:54

    From the docs (here, from the glob module):

    (For tilde and shell variable expansion, use os.path.expanduser() and os.path.expandvars().)

    You want os.path.expanduser().

    0 讨论(0)
  • 2020-12-11 09:08
    os.environ["HOME"] = "/Users/partuck/
    os.path.expanduser("~/cache_dir/bla")
    

    (@jedwards answer pointed out expanduser)

    0 讨论(0)
提交回复
热议问题