Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 for maya:Why can';我不能在包含通配符的表达式中使用变量吗?_Python_Python 3.x_Scripting_Maya - Fatal编程技术网

Python for maya:Why can';我不能在包含通配符的表达式中使用变量吗?

Python for maya:Why can';我不能在包含通配符的表达式中使用变量吗?,python,python-3.x,scripting,maya,Python,Python 3.x,Scripting,Maya,我试图在maya中使用“ls”python命令,以通配符形式列出名称中具有匹配字符串的特定对象 简单的示例代码如下: from maya.cmds import * list = ls('mesh*') from maya.cmds import * name = 'mesh' list = ls('name*') from maya.cmds import * name = 'mesh' list = ls('name' + '*') 这段代码可以工作,并将返回名称中包含匹配字符串的对象

我试图在maya中使用“ls”python命令,以通配符形式列出名称中具有匹配字符串的特定对象

简单的示例代码如下:

from maya.cmds import *
list = ls('mesh*')
from maya.cmds import *
name = 'mesh'
list = ls('name*')
from maya.cmds import *
name = 'mesh'
list = ls('name' + '*')
这段代码可以工作,并将返回名称中包含匹配字符串的对象列表,但是,我希望使用变量而不是字符串中的硬编码。更像这样:

from maya.cmds import *
list = ls('mesh*')
from maya.cmds import *
name = 'mesh'
list = ls('name*')
from maya.cmds import *
name = 'mesh'
list = ls('name' + '*')
或者像这样:

from maya.cmds import *
list = ls('mesh*')
from maya.cmds import *
name = 'mesh'
list = ls('name*')
from maya.cmds import *
name = 'mesh'
list = ls('name' + '*')
但是,在这两个示例中,它都返回一个空列表,与第一个不同。我不确定为什么会出现这种情况,因为在这些示例中,字符串concatation应该像第一个示例一样显示为“mesh*”。我在这个网站上找不到答案,所以我选择问一个问题

多谢各位

法学博士


另外,如果有更好的方法在maya中查询对象,请让我知道它的名称,我将对此进行一些研究。目前,这是我知道的在maya中搜索对象的唯一方法。

只要在变量
名称
周围添加引号,就像这样
'name'
,实际上您只是创建了一个新字符串,而不是引用变量

有许多不同的方法可以在Python中连接字符串以实现您想要的效果:

使用
%

'name%s' % '*'
使用字符串的
格式
方法:

'{}*'.format(name)
只需使用
+

name + '*'
所有这些都将产生相同的输出,
'mesh*”
,并将与
cmds.ls一起使用


就我个人而言,我坚持使用
格式

只要您在变量
名称
周围添加引号,就像这样
'name'
,您实际上只是在创建一个新字符串,而不是引用变量

有许多不同的方法可以在Python中连接字符串以实现您想要的效果:

使用
%

'name%s' % '*'
使用字符串的
格式
方法:

'{}*'.format(name)
只需使用
+

name + '*'
所有这些都将产生相同的输出,
'mesh*”
,并将与
cmds.ls一起使用

就我个人而言,我坚持使用
格式

在。您没有引用变量
name
Take-tour at。您没有引用变量
名称