stumbled on python iif() equivalent, at last

Laurent Szyster laurent.szyster at q-survey.be
Sat Jun 23 11:42:22 EDT 2001


as i was peeking into compileall.py, i stumbled on:

    cfile = fullname + (__debug__ and 'c' or 'o')

surprise:

    Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license" for more information.
    IDLE 0.6 -- press F1 for help
    >>> __debug__ and 'c' or 'o'
    'c'

so, there's an iif (condition, is_true, is_false) python equivalent:

    >>> 1 and 'c' or 'o'
    'c'
    >>> 0 and 'c' or 'o'
    'c'

nice-to-have for one-liner :-)


Laurent



More information about the Python-list mailing list