这里是createPeliMelo.py的开头
def creation(path,session):
myPathFile=path+session+'.txt'
print myPathFile
pelimeloFile = open(path+session+'.txt', 'r')
with pelimeloFile as inf:
data = json.loads(inf.read())
这是我在 Maya 中的 Python 脚本:
import maya.cmds as cmds
import json
import os
from itertools import islice
import createPeliMelo as PeliMelo
PeliMelo.creation('C:/Users/francesco/Desktop/pelimelo video printemps/','session5723')
这是我得到的错误:
Error: line 1: NameError: file C:/Users/francesco/Documents/maya/2016/scripts\createPeliMelo.py line 17: global name 'json' is not defined #
第 17 行是:data = json.loads(inf.read())
我哪里错了?
最佳答案
当你导入一些东西时,该导入只适用于你导入它的文件。这意味着如果你想在 createPeliMelo.py
中使用 json
你需要在该文件中执行 import json
,而不是您的第二个脚本。从一个文件导入不会传播到另一个文件。
关于python - 全局名称 'json' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42987068/