python - 属性错误 : 'PosixPath' object has no attribute 'path'

标签 python

我有一个我正在尝试执行的 python 脚本,但我不确定它是如何执行的。我不会用 Python 编程,所以我不熟悉这门语言。 Here is the link to the script i'm trying to use.还有一个 link the configuration it's using if you wish to see it.然而,似乎与此处相关的所有内容都是设置我的路径,我知道这是正确的,因为其他脚本(此处未链接)与该文件中的配置按预期工作。

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

$ lectures.py new

但我得到以下回溯
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'

此外,我的python版本
$ python --version
Python 3.8.1

编辑:
I wanted to add the reference as well for what I am trying to follow

最佳答案

通过你的代码,我想你的意思可能是:

self.root = course

在那条线上。
Path.cwd()返回:

... the current working directory, that is, the directory from where you run the script.



也就是说,要么是 WindowsPath() PosixPath 目的。我相信是PosixPath为您,您可以验证:
import os
print(os.name)
# posix -> Linux
# nt -> Windows

这没有属性 path ,这就是你的口译员告诉你的。

关于python - 属性错误 : 'PosixPath' object has no attribute 'path' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59693174/

相关文章:

Python字典,其中多个键以内存有效的方式指向同一列表

python - 是否有更多的 pythonic,可能是一个衬里,来迭代列表中的字符串?

python - Python 中重复字符串而不进行乘法运算

python - 使用策展人python API无法过滤和删除Elasticsearch的旧索引

python - 有没有办法验证从源代码构建的 Python 解释器是否正确?

python - 动态自定义 django 管理列?

Python pymssql - 连接到命名实例

python - 如何使用python将文件分块传输到azure blob存储而不写入文件

python - 解析CSV文件并修改列

python - 使用数字序列格式化字符串以生成按 Python 中的数字排序的字符串列表