简体   繁体   English

使用JSON.Load时Python中出现错误:未定义名称'isinstance'

[英]Error in Python when using JSON.Load : name 'isinstance' is not defined

Python noob here. Python noob在这里。 I'm trying to execute a Python script but on json.load it fails with the error message name 'isinstance' is not defined . 我正在尝试执行Python脚本,但是在json.load上它失败,错误消息name 'isinstance' is not defined

Since json is a library that comes with the Python installation (3.4.2) I find this very strange. 由于json是Python安装(3.4.2)随附的库,因此我觉得这很奇怪。 Has anyone encountered anything similar and/or may have a solution? 是否有人遇到类似问题和/或可能有解决方案?

The code looks like this 代码看起来像这样

try:
    prefs_path = os.path.join(os.path.expanduser("~"), ".foo")
    prefs_file = open(prefs_path)
    prefs_hash = json.load(prefs_file)
except Exception as e:
    raise Exception(str(e))

Thanks guys! 多谢你们! Yea, it actually came up that something was wrong in the file I was trying to read. 是的,实际上是我尝试读取的文件中出现问题。 Once I edited it and fixed the problem the Python script works. 编辑并修复问题后,Python脚本即可工作。

Funny tho how a typo in the json file would cause such an error, complaining about isinstance()! 有趣的是,json文件中的错字会引起这样的错误,抱怨isinstance()!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM