Using List Comprehensions on Files : List Comprehension « List « Python Tutorial






f = open('script1.py')
lines = f.readlines(  )
print lines

lines = [line.rstrip(  ) for line in lines]
print lines








7.15.List Comprehension
7.15.1.List Comprehension
7.15.2.List Comprehensions in build Connection String, Step by Step
7.15.3.Filtering Lists: [mapping-expression for element in source-list if filter-expression]
7.15.4.List Type Operators and List Comprehensions
7.15.5.Extended List Comprehension Syntax
7.15.6.Using List Comprehensions on Files