Dynamic generated json file read I have an external script that generates a json file with rotations. I want to read this json file with blender, but it seems there is a problem with the json reading functions in blender.

import json
from pprint import pprint

with open('blendjson.json') as data_file: #This line throws this error : "Python script fail, look in the console for now..."  
    data = json.load(data_file)


coordx = data['coordx']
coordy = data['coordy']

#This works as long as I can get values for the varibales coordx and coordy :
bpy.ops.transform.rotate(value=coordx, axis=(-1, -0, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)

bpy.ops.transform.rotate(value=coordy, axis=(-0, -1, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)


This script works in itself when launched through the terminal (python blendjson.py), except for the bpy objects of course.
Is there a way to read the json file, or a better way to get these two variables ?
As Rich has pointed out, the file you are trying to open does not reside at the location Blender starts up from.

By running os.getcwd() you can see, that you are working in the folder where you installed Blender to.

To open the file (which I guess is residing in your homefolder), you can use the os.path module:

os.path.expanduser('~')


This will give you your homefolder, which you can then combine with other directories using

os.path.join(direc1, direc2, file)


Another option is to use os.chdir(directory) to move to a new working directory first, before opening the file (e.g. you can use os.chdir(os.path.dirname(__file__)) to move to the folder where your python file sits)

Happy coding, Mr. Anderson!

Hint: When using different operation systems, make sure you always use the os.path module, as it can handle the differences in path separators ('\ for Windows, / for Linux and so on). E.g. os.path.abspath(filepath) to get a proper absolute path for the provided filepath.