[英]AttributeError: 'PosixPath' object has no attribute 'path'
I have a python script that I'm trying to execute but i'm not sure how it's meant to be executed.我有一个我正在尝试执行的 python 脚本,但我不确定它是如何执行的。 I don't program in Python so i'm unfamiliar with the language.我不会用 Python 编程,所以我不熟悉这门语言。 Here is the link to the script i'm trying to use.这是我尝试使用的脚本的链接。 Also, a link the configuration it's using if you wish to see it.此外,如果您想查看它正在使用的配置的链接。 All it seems to do for what's relevant here, however, is set my path which I know is correct since other scripts (not linked here) work as expected with the configuration in that file.然而,似乎与此处相关的所有内容都是设置我的路径,我知道这是正确的,因为其他脚本(此处未链接)与该文件中的配置按预期工作。
Having a look at the script, I believe that the script is meant to be ran with the command line arguments: view, new, init.看看脚本,我相信脚本应该使用命令行参数运行:view、new、init。 Thus, I ran the following in my terminal因此,我在终端中运行了以下内容
$ lectures.py new
But I get the following traceback但我得到以下回溯
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'
Furthermore, my python version此外,我的python版本
$ python --version
Python 3.8.1
EDIT: I wanted to add the reference as well for what I am trying to follow编辑:我还想为我想要遵循的内容添加参考
Going through your code, I think you might mean:通过你的代码,我想你的意思可能是:
self.root = course
at that line.在那条线上。
Path.cwd()
returns: Path.cwd()
返回:
... the current working directory, that is, the directory from where you run the script. ... 当前工作目录,即运行脚本的目录。
that is, either a WindowsPath()
or a PosixPath
object.即, WindowsPath()
或PosixPath
对象。 I believe it is PosixPath
for you, and you can verify with:我相信这对您来说是PosixPath
,您可以通过以下方式进行验证:
import os
print(os.name)
# posix -> Linux
# nt -> Windows
This has no attribute path
, and this is what your Interpreter tells you.这没有属性path
,这就是您的解释器告诉您的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.