小编Ang*_*uks的帖子

NameError: name '__file__' 未定义

我正在尝试使用以下方法将脚本的路径存储到变量中:

os.path.abspath(os.path.dirname(__file__))
Run Code Online (Sandbox Code Playgroud)

但是,它不断返回name '__file__' is not defined错误。

here = os.path.dirname(os.path.abspath(__file__))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__file__' is not defined
Run Code Online (Sandbox Code Playgroud)

python nameerror

1
推荐指数
2
解决办法
6339
查看次数

标签 统计

nameerror ×1

python ×1