AttributeError:“PosixPath”对象没有属性“path”

Van*_*Van 12 python

我有一个正在尝试执行的 python 脚本,但我不确定它是如何执行的。我不使用 Python 编程,所以我不熟悉该语言。这是我尝试使用的脚本的链接。 另外,如果您想查看它所使用的配置的链接。然而,它似乎对此处相关的内容所做的只是设置我的路径,我知道该路径是正确的,因为其他脚本(此处未链接)按照该文件中的配置按预期工作。

看一下脚本,我相信该脚本应该使用命令行参数运行:view、new、init。因此,我在终端中运行了以下命令

$ lectures.py new
Run Code Online (Sandbox Code Playgroud)

但我得到以下回溯

Traceback (most recent call last):
  File "/usr/bin/lectures.py", line 156, in <module>
    lectures = Lectures(Path.cwd())
  File "/usr/bin/lectures.py", line 60, in __init__
    self.root = course.path
AttributeError: 'PosixPath' object has no attribute 'path'
Run Code Online (Sandbox Code Playgroud)

此外,我的Python版本

$ python --version
Python 3.8.1
Run Code Online (Sandbox Code Playgroud)

编辑: 我想添加参考以及我想要遵循的内容

Jai*_*har 4

浏览你的代码,我想你的意思可能是:

self.root = course
Run Code Online (Sandbox Code Playgroud)

在那条线上。

Path.cwd()返回:

...当前工作目录,即运行脚本的目录。

也就是说,要么是一个对象WindowsPath(),要么是一个PosixPath对象。我相信它适合PosixPath您,您可以通过以下方式进行验证:

import os
print(os.name)
# posix -> Linux
# nt -> Windows
Run Code Online (Sandbox Code Playgroud)

它没有 attribute path,这就是你的解释器告诉你的。