python touchdesigner的Python-switch语句最佳

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python touchdesigner的Python-switch语句最佳相关的知识,希望对你有一定的参考价值。

def switcher(func_name, vals):

	functions 	= {
		"Add" 		: Add,
		"Subtract"	: Subtract,
		"Multiply"	: Multiply,
		"Divide"	: Divide
	}

	active_function = functions.get(func_name)
	result 			= active_function(vals)

	return result

def Add(vals):
	sum_val 	= 0
	for item in vals:
		sum_val += item
	return sum_val

def Subtract(vals):
	sum_val 	= vals[0]
	for item in vals[1:]:
		sum_val -= item
	return sum_val

def Multiply(vals):
	if len(vals) > 2:
		sum_val = 'Invalid Call - "Multiply" only takes two vals'
	else:
		sum_val 	= vals[0] * vals[1]
	return sum_val

def Divide(vals):
	if len(vals) > 2:
		sum_val = 'Invalid Call - "Divide" only takes two vals'
	else:
		sum_val 	= vals[0] / vals[1]
	return sum_val

vals 		= [3, 4]
print( switcher("Multiply", vals) )

以上是关于python touchdesigner的Python-switch语句最佳的主要内容,如果未能解决你的问题,请参考以下文章

python touchdesigner的Python-switch语句好

python touchdesigner的Python-switch语句最差

python 使用自定义环境值启动TouchDesigner

python touchdesigner-通用代码分割-jobEXT-示例

python touchdesigner-通用代码分割-generalEXT-示例

python 怎么,不至延迟功能于TouchDesigner