【问题标题】:os.getcwd() returns a slash (/)os.getcwd() 返回一个斜杠 (/)
【发布时间】:2019-08-01 14:59:22
【问题描述】:

我有一个在 macOS 上的 Atom 编辑器中编写的 python 3.6 脚本。该脚本经常使用 os.getcwd() 并且一直运行良好。我昨晚重新启动了我的电脑,更新了 Atom 包,突然它坏了。使用 print 语句,os.getcwd() 现在只返回“/”。

尝试了多个脚本,都在不同的目录中。

import os
print(os.getcwd())

预期:/Users/kpaddock/Desktop/Python/SCID-Report-DRAFT

实际输出:/

【问题讨论】:

    标签: python macos path atom-editor getcwd


    【解决方案1】:

    我的错,我看的不够仔细。原来os.getcwd() 并不总是准确的?替换为os.path.abspath(os.path.dirname(__file__)) 就可以了。

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 2012-05-22
      • 2018-01-01
      • 1970-01-01
      相关资源
      最近更新 更多