2

这是一个特定于在 booggie 2 中使用 python 脚本的问题。

我想将多个字符串返回到序列中并将它们存储在变量中。

脚本应如下所示:

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): string, string"""

    return "string_1", "string_2"

在我想要的序列中:

(param_1, param_2) = getConfiguration(1)

请注意:booggie 项目不再存在,但导致开发了涵盖相同功能的Soley Studio 。

4

4 回答 4

6

booggie 2 中的脚本仅限于单个返回值。但是您可以返回一个包含您的字符串的数组。遗憾的是 Python 数组与 GrGen 数组不同,因此我们需要先转换它们。

所以你的例子看起来像这样:

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): array<string>"""

    #TypeHelper in booggie 2 contains conversion methods from Python to GrGen types
    return TypeHelper.ToSeqArray(["string_1", "string_2"])
于 2012-10-31T08:23:27.450 回答
3

返回一个元组

return ("string_1", "string_2")

看这个例子

In [124]: def f():
   .....:     return (1,2)
   .....:

In [125]: a, b = f()

In [126]: a
Out[126]: 1

In [127]: b
Out[127]: 2
于 2012-10-31T07:58:53.140 回答
2

Still, it's not possible to return multiple values but a python list is now converted into a C#-array that works in the sequence.

The python script itself should look like this

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): array<string>"""

    return ["feature_1", "feature_2"]

In the sequence, you can then use this list as if it was an array:

config_list:array<string>               # initialize array of string
(config_list) = getConfigurationList(1) # assign script output to that array

{first_item = config_list[0]}           # get the first string("feature_1") 
{second_item = config_list[1]}          # get the second string("feature_2") 
于 2012-10-31T11:23:51.147 回答
1

对于上面的示例,我建议使用以下代码来访问数组中的条目(按顺序):

    config_list:array<string>               # initialize array of string
    (config_list) = getConfigurationList(1) # assign script output to that array

    {first_item = config_list[0]}           # get the first string("feature_1") 
    {second_item = config_list[1]}          # get the second string("feature_2") 
于 2013-01-18T16:46:51.497 回答