python中的多值返回模式
multiret的Python项目详细描述
原来,您有:
deffunc():return1printfunc()+func()
然后您决定func()可以返回一些额外的信息,但是您不想破坏以前的代码 (或逐一修改)。 看起来
deffunc():return1,"extra info"value,extra=func()printvalue# 1 (expected)printextra# extra info (expected)printfunc()+func()# (1, 'extra info', 1, 'extra info') (not expected, we want the previous behaviour, i.e. 2)
先前的代码(func() + func())已损坏。你得把它修好。
解决方案是根据答案改编的