5 ms·
`os.open` is a low-level interface whose semantics are platform-dependent. The Python analogue is the builtin `open`, which documents that it raises IOError on
by jemfinch 15y ago
`os.open` is a low-level interface whose semantics are platform-dependent. The Python analogue is the builtin `open`, which documents that it raises IOError on a failure to open a file: http://docs.python.org/library/functions.html#open http://docs.python.org/library/functions.html#open .
- JoachimSchipper 15y agoTrue, but you have to dig a lot to find any details. The above code is easy to write from a good man page (OpenBSD's, in this case.) (Also, open(2) has all these options for a reason; think symlink races. Python's open() is not sufficient.)
- sausagefeet 15y agoNote, open is not part of C. A better comparison would be fopen which, according to the C99 draft I have, just returns NULL on failure.
- JoachimSchipper 15y agoYou're technically correct, but that's not the "C" being discussed in this article. Also, fopen(3) on OpenBSD does document values errno after failure (by reference to the malloc(3) and open(2) man pages), and I expect that any reasonable system does likewise.