this_line = boolselect(dummy_flag," Dummy line \ n",infile.readline()) 副作用是简单函数的主要原因 通常不能取代完整的条件三元运算符。 请参阅google进行三元运算符辩论,并在clp中查看其他 讨论现在。 问候。 Mel。 Some poeple might be disturbed by what it would do with this_line = boolselect (dummy_flag, "Dummy line\n", infile.readline()) Side-effects are the main reason that a simple functioncan''t generally replace a full conditional ternary operator.See google for the ternary operator debate, and see the otherdiscussion in clp right now. Regards. Mel. 这不起作用因为两个结果都得到了评估两种方式。例如, boolselect(x == 0,f(x),g(x)) 调用f和g。你需要类似 (lambda:g(x),lambda:f(x))[bool(condition)]() That doesn''t work because both results get evaluated either way. E.g. boolselect(x==0, f(x), g(x)) calls both f and g. You need something like (lambda: g(x), lambda: f(x))[bool(condition)]() 这篇关于提案:模拟C?:运算符的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 02:24