Python 将在不同函数中生成的多个列表中的内容传递到文件

Python 将在不同函数中生成的多个列表中的内容传递到文件,python,Python,我有3个函数,它们生成三个不同的列表。我试图生成一个mel脚本,它是一个文本文件,将写入从这三个列表中获取的值。所有三个列表都有相同数量的值。这些列表中的所有值都是动画数据,因此必须在mel脚本中传递这些值才能在Maya中驱动动画。所有这些列表值都是浮点数 func1() : generates tlist func2() : generates list1 func3() : generates list2 def mel_script() : """ G

我有3个函数,它们生成三个不同的列表。我试图生成一个mel脚本,它是一个文本文件,将写入从这三个列表中获取的值。所有三个列表都有相同数量的值。这些列表中的所有值都是动画数据,因此必须在mel脚本中传递这些值才能在Maya中驱动动画。所有这些列表值都是浮点数

func1() :
    generates tlist

func2() :
    generates list1

func3() :
    generates list2  

def mel_script() :
  """ Generating the mel script with the animation information """
  with open("mel.txt", "w") as melFile :
      melFile.write(setKeyframe "blend_shape.lip_round";
                    setKeyframe "blend_shape.jaw_open";

                    currentTime 0 ;
                    setAttr "blend_shape.lip_round" 0;
                    setAttr "blend_shape.jaw_open" 0;
                    setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"}; 

                    currentTime (first value of tlist) ;
                    setAttr "blend_shape.lip_round" (first value of list1);
                    setAttr "blend_shape.jaw_open" (first value of list2);
                    setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"};

                    currentTime (second value of tlist) ;
                    setAttr "blend_shape.lip_round" (second value of list1);
                    setAttr "blend_shape.jaw_open" (second value of list2);
                    setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"};                       
                   ........
                   ........
文件中的前6行是默认值。mel脚本中的文本应一直持续到每个列表中的最后一个值。我怎样才能做到这一点?多谢各位

使用
zip

for x, y, z in zip(func1(), func2(), func3()):
    melFile.write("currentTime %f" % x)
    melFile.write('setAttr "blend_shape.lip_round" %f' % y)
    melFile.write('setAttr "blend_shape.jaw_open" %f' % z)

添加要生成的所有其他样板文件,并尝试想出比
x
y
z
z

更好的变量名,我必须在mel_script()函数中将所有列表作为参数传递?但我该把这个函数称为什么?@zingy:谁在谈论传递参数?我发布的代码段中没有函数定义。很抱歉,我还没有理解。但是我应该把这个代码放在哪里呢?它在mel_script()函数中吗?@zingy:是的,在
mel_script
中。函数中生成的列表的值可以这样传递吗?我的意思是仅仅指功能?