Ternary


22
Jul 10

Python ternary operator

Python has no ternary operator, or has it? At least not directly, we had a discussion about possible solutions in the #python IRC channel on FreeNode and after some filddling I came up with this hack abusing the Python slicing magic: class Ternary(object): ''' Ternary-ish emulation, it looks like C-style ternary operator:: x = a [...]