0

Python noob here. I'm trying to execute a Python script but on json.load it fails with the error message name 'isinstance' is not defined.

Since json is a library that comes with the Python installation (3.4.2) I find this very strange. 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))
J. Ghyllebert
  • 2,009
  • 1
  • 29
  • 35
Z317
  • 1
  • 1
    And `prefs_file` is in fact a valid JSON file? Could you remove the `try/except` block and post the entire traceback? – Tim Pietzcker Dec 11 '14 at 12:12
  • Your exception handler is indeed worse than useless: it's harmfull. Without it you'd get the full traceback, and much more hints about what went wrong. – bruno desthuilliers Dec 11 '14 at 12:41

1 Answers1

0

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.

Funny tho how a typo in the json file would cause such an error, complaining about isinstance()!

Z317
  • 1