【问题标题】:Python: os.path.exists failing on "~/foo" [duplicate]Python:os.path.exists 在“~/foo”上失败 [重复]
【发布时间】:2014-05-03 22:42:43
【问题描述】:

我正在尝试通过运行检查目录是否存在

self.path = '~/foo'
    if not os.path.exists(self.path):
        os.makedirs(self.path)

在 Ubuntu 虚拟机上。尽管此目录不存在,但它不会创建该目录。事实上,使用 makedirs 命令正上方的 print 语句。知道它可能是什么吗?

【问题讨论】:

    标签: python ubuntu directory os.path


    【解决方案1】:

    您可能想先在路径上os.path.expanduser...

    【讨论】:

      猜你喜欢
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      相关资源
      最近更新 更多