Continue 和 break 语句做同样的事情
Continue and break statement doing the same thing
这是我今天的第二个新手问题...请耐心等待。所以这应该通过 'nothing'
和 'persp'
循环,同时由于 continue;
语句仍然 renaming/printing After:[u’concrete_file1’]
,但我只是得到空括号。我 运行 没有这个的相同功能:
if not (maya.cmds.ls(texture) and
maya.cmds.nodeType(texture)=='file'):
continue;
并且没有 'nothing'
和 'persp'
并且它工作正常所以我假设问题出在某个地方,但是在摆弄了一段时间之后我仍然不知道它是什么是...这可能是一些超级简单的答案,但我在学习这些东西的第 2 天,所以 ¯\_(ツ)_/¯
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 脚本编辑器来编写所有这些内容,是否有更好的编辑器可能更容易?
当 if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'):
不正确时,在 continue;
运行 之后包含一个 else
来进行陈述。
这里发生的是,只有一个条件。只要为真,它就会计算 continue;
并跳过其余语句。但是,只要这不是真的,它 也 会跳过 new_texture_names.append(maya.cmds.rename(texture, '%s%s'%(pre, texture)));
,因为它在 if
条件内。
这是我今天的第二个新手问题...请耐心等待。所以这应该通过 'nothing'
和 'persp'
循环,同时由于 continue;
语句仍然 renaming/printing After:[u’concrete_file1’]
,但我只是得到空括号。我 运行 没有这个的相同功能:
if not (maya.cmds.ls(texture) and
maya.cmds.nodeType(texture)=='file'):
continue;
并且没有 'nothing'
和 'persp'
并且它工作正常所以我假设问题出在某个地方,但是在摆弄了一段时间之后我仍然不知道它是什么是...这可能是一些超级简单的答案,但我在学习这些东西的第 2 天,所以 ¯\_(ツ)_/¯
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 脚本编辑器来编写所有这些内容,是否有更好的编辑器可能更容易?
当 if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'):
不正确时,在 continue;
运行 之后包含一个 else
来进行陈述。
这里发生的是,只有一个条件。只要为真,它就会计算 continue;
并跳过其余语句。但是,只要这不是真的,它 也 会跳过 new_texture_names.append(maya.cmds.rename(texture, '%s%s'%(pre, texture)));
,因为它在 if
条件内。