这是一个特定于在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的开发,它涵盖了相同的功能。
发布于 2012-10-31 19:23:51
尽管如此,不可能返回多个值,但是python列表现在被转换为按序列工作的C#数组。
python脚本本身应该如下所示
def getConfiguration(config_id):
""" Signature: getConfiguration(int): array<string>"""
return ["feature_1", "feature_2"]
在序列中,您可以使用此列表,就像它是一个数组一样:
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-31 16:23:27
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-31 15:58:53
返回元组
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
https://stackoverflow.com/questions/13153506
复制相似问题