Python Continue和break语句执行相同的操作
这是我今天的第二个问题。。。所以请容忍我。因此,这应该循环通过Python Continue和break语句执行相同的操作,python,maya,Python,Maya,这是我今天的第二个问题。。。所以请容忍我。因此,这应该循环通过'nothing'和'persp',同时仍然在[u'concrete\u file1']之后重命名/打印,因为继续语句,但我只得到空括号。我运行了相同的函数,但没有: if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'): continue; 如果没有'nothing'和'persp',它工
'nothing'
和'persp'
,同时仍然在[u'concrete\u file1']之后重命名/打印,因为继续代码>语句,但我只得到空括号。我运行了相同的函数,但没有:
if not (maya.cmds.ls(texture) and
maya.cmds.nodeType(texture)=='file'):
continue;
如果没有'nothing'
和'persp'
,它工作得很好,所以我假设问题在哪里,但在摆弄了一段时间后,我仍然不知道它是什么。。。这可能是一个非常简单的答案,但我正在第二天学习这些东西,所以\_(ツ)_/“
def process_all_textures(**kwargs):
pre = kwargs.setdefault('prefix');
if (isinstance(pre, str) or
isinstance(pre, unicode)):
if not pre[-1] == '_':
pre += '_';
else: pre = '';
textures = kwargs.setdefault('texture_nodes');
new_texture_names = [];
if (isinstance(textures, list) or
isinstance(textures, tuple)):
for texture in textures:
if not (maya.cmds.ls(texture) and
maya.cmds.nodeType(texture)=='file'):
continue;
new_texture_names.append(
maya.cmds.rename(
texture,
'%s%s'%(pre, texture)
)
);
return new_texture_names;
else:
maya.cmds.error('No texture nodes specified');
#Should skip over the 2 invalid objects ('nothing' & 'persp')
#because of the continue statement...
new_textures= [
'nothing',
'persp',
maya.cmds.shadingNode('file', asTexture=True)
];
print ('Before: %s'%new_textures);
new_textures = process_all_textures(
texture_nodes = new_textures,
prefix = 'concrete_'
);
print ('After: %s'%new_textures);
Before: ['nothing', 'persp', u'file1']
After: []
另外,我只是在使用Maya脚本编辑器来编写所有这些内容,是否有更好的编辑器更容易?包括否则
以在继续之后执行语句;
在未执行时运行(Maya.cmds.ls(纹理)和Maya.cmds.nodeType(纹理)='file'):
不正确
这里发生的情况是,只有一个条件。如果该条件为真,它将计算continue;
并跳过其余语句。但是,如果该条件不为真,它也将跳过new\u texture\u names.append(maya.cmds.rename(纹理,'%s%s'(pre,texture)))
因为这在if
条件中。如果你知道函数的参数可以是什么(前缀
,纹理节点
,等等),我看不到使用**kwargs和dict.setdefault
)的好处,而不仅仅是像处理所有纹理(前缀=无,纹理节点=无)
--dict.setdefault
没有第二个参数就可以做到这一点。idk我现在只是在看一本书,因为我是新手,他们使用**kwargs。这将导致一个简短的Python工具,所以以后可能会有更多内容?