Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Read a file line by line

Rust

#![allow(unused)]
fn main() {
let f = File::open("foo.txt").unwrap();
for line in BufReader::new(&f).lines().filter_map(Result::ok) {
    // The line doesn't contain trailing CR/LF
}
}

Python

for line in open("foo.txt"):
    # The line contains trailing CR/LF