继续和中断语句做相同的事情

2024-04-29 22:06:13 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我今天的第二个问题。。。所以请容忍我。所以这应该是在'nothing''persp'之间循环,同时仍然因为continue;语句而重命名/打印After:[u’concrete_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脚本编辑器来编写所有这些,有没有更好的编辑器,可能更容易


Tags: newifnotprekwargsfileisinstancecmds
1条回答
网友
1楼 · 发布于 2024-04-29 22:06:13

包含一个else,以便在if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'):不为true时运行continue;之后的语句

这里发生的是,只有一个条件。只要这是真的,它就会计算continue;并跳过其余语句。但是,如果不是这样,它也会跳过new_texture_names.append(maya.cmds.rename(texture, '%s%s'%(pre, texture)));,因为这在if条件内

相关问题 更多 >