Python2中的可变长度optionals参数(*args)导致错误
我试图在Python2中运行以下代码,但出现无效语法错误Python2中的可变长度optionals参数(*args)导致错误,python,python-2.7,python-2.x,optional-arguments,Python,Python 2.7,Python 2.x,Optional Arguments,我试图在Python2中运行以下代码,但出现无效语法错误 columns = ["col1"] funcs = val_to_list(funcs) exprs = [] for col_name in columns: for func in funcs: exprs.append((func, (col_name, *args))) 我从Python3项目中获取了这段代码,但我想让它在Python2中工作。我尝试了几
columns = ["col1"]
funcs = val_to_list(funcs)
exprs = []
for col_name in columns:
for func in funcs:
exprs.append((func, (col_name, *args)))
我从Python3项目中获取了这段代码,但我想让它在Python2中工作。我尝试了几种组合,但都不起作用。请帮忙 (col\u name,*args)
创建一个新元组,第一个元素是col\u name
,后面是args
中的所有元素。此语法被调用并被使用
只需通过连接创建元组:
t = (col_name,) + args # assuming args is a tuple too
exprs.append((func, t))
如果args
本身还不是元组,请将其转换为:
t = (col_name,) + tuple(args) # works with any iterable.
exprs.append((func, t))
(col\u name,*args)
创建一个新元组,第一个元素是col\u name
,后面是args
中的所有元素。此语法被调用并被使用
只需通过连接创建元组:
t = (col_name,) + args # assuming args is a tuple too
exprs.append((func, t))
如果args
本身还不是元组,请将其转换为:
t = (col_name,) + tuple(args) # works with any iterable.
exprs.append((func, t))
我想让它在Python2中工作。为什么?由于我公司环境的限制。很多生产代码仍在Python 2中,因此必须与现有代码集成。我想让它在Python 2中工作。为什么?由于我公司环境的限制,很多生产代码仍在Python 2中,因此必须与现有代码集成。