Python 全球名称';json';没有定义
下面是createPeliMelo.py的开始Python 全球名称';json';没有定义,python,json,maya,Python,Json,Maya,下面是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
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')
以下是我得到的错误:
错误:第1行:名称错误:文件C:/Users/francesco/Documents/maya/2016/scripts\createPeliMelo.py行
17:未定义全局名称“json”#
第17行是:data=json.loads(inf.read())
我哪里错了?导入某些内容时,该导入仅适用于导入该内容的文件。这意味着,如果要在
createPeliMelo.py
中使用json
,则需要在该文件中执行import json
,而不是第二个脚本。从一个文件导入不会传播到另一个文件。您需要在createPeliMelo.pydef创建(路径,会话)中导入json:导入json导入maya.cmds作为cmds导入json导入os@fransua将导入放在文件的最顶端。它可以工作。。。除了现在我有一条新的错误消息:“未定义全局名称“cmds”#”,尽管我还添加了“import maya.cmds as cmds”