For review: PEP 308 - If-then-else expression
Andrew Koenig
ark at research.att.com
Mon Feb 10 17:19:48 EST 2003
Michele> Moreover I fear abuses like
Michele> files=[f for f in os.listdir(mydir) \
Michele> if (if issource: f.endswith('.py') else: True)]
Michele> to retrieve all the files or only the source files (this is a
Michele> real case life where I would like to use the ternary
Michele> operator, but NOT in this form!)
I don't see this is a case for the ternary operator at all. Surely it
is better to write
files=[f for f in os.listdir(mydir) \
if not issource or f.endswith('.py')]
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list