As you figured out, the function read_line can be used from the reader_util
implementation from module io
~~~~
import io::reader_util;
#[doc = "reads the entire file line by line except the first line"]
fn main(args: [str]) {
if args.len() == 1u {
fail #fmt("usage: %s <filename>", args[0]);
}
let r = io::file_reader(args[1]); // r is result<reader, err_str>
if result::failure(r) {
fail result::get_err(r);
}
let rdr = result::get(r);
rdr.read_line(); // skip line
while !rdr.eof() {
io::println(rdr.read_line());
}
}
~~~~
I don't think Rust lets you catch exceptions while reading the stream as
you can't do much about it*.
* Error handling in Rust is unrecoverable unwinding
On 3 April 2012 13:34, Mic <[email protected]> wrote:
> Hello,
> I found read_line, but I do not how to convert the following Python code
> (skip first line and print all other lines from a file) to Rust.
>
> f = open(file_name, 'r')
> f.next() #skip line
> for line in f:
> print line
> f.close()
>
> How rust handle exceptions?
>
> Thank you in advance.
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev