Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 全球名称';json';没有定义_Python_Json_Maya - Fatal编程技术网

Python 全球名称';json';没有定义

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

下面是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')
以下是我得到的错误:

错误:第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”