[issue19657] List comprehension conditional evaluation order seems backwards

2013-11-19 Thread R. David Murray
Changes by R. David Murray : -- resolution: -> invalid stage: -> committed/rejected status: open -> closed type: -> behavior ___ Python tracker ___ ___

[issue19657] List comprehension conditional evaluation order seems backwards

2013-11-19 Thread Peter Otten
Peter Otten added the comment: I believe you are misinterpreting what you are seeing. Empty lines read from a file do not produce an empty string, you get "\n" instead which is true in a boolean context. Try [line.split()[0] for line in lines if line.strip() and not line.startswith("#")] or

[issue19657] List comprehension conditional evaluation order seems backwards

2013-11-19 Thread Garrett Cooper
New submission from Garrett Cooper: I was a bit surprised when I ran into this issue when porting some nose tests from Windows to Linux: #!/usr/bin/env python with open('/etc/services') as fd: lines = fd.readlines() lines.append('') SERVICES = [line.split()[0] for line in lines