raise statement on a conditional expression

后端 未结 4 478
梦如初夏
梦如初夏 2020-12-29 03:38

Following \"Samurai principle\", I\'m trying to do this on my functions but seems it\'s wrong...

return  if  else raise 

        
4条回答
  •  自闭症患者
    2020-12-29 04:20

    If you absolutely want to raise in an expression, you could do

    def raiser(ex): raise ex
    
    return  if  else raiser()
    

    This "tries" to return the return value of raiser(), which would be None, if there was no unconditional raise in the function.

提交回复
热议问题