(redirected from Main.ReadAFileIntoAListStrippingNewlines)
Using list comprehension:
- with open("filespec") as f:
- lines = [x.strip for x in f.readlines()]
Contrast with the perl idiom:
- open (FH, "<filespec");
- @lines = <FH>;
- chomp(@lines);
And the same in Ruby:
lines = IO.readlines("filespec").map{|l| l.chomp}
| Tags: | Categories: ComputerStuff |
Recent Changes |
Printable View |
Page History |
Edit Page
Page last modified on April 16, 2012, at 11:43 AM by tamara