Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95850
| Date | 2015-09-02 12:08 +1000 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Low level file descriptors and high-level Python files |
| References | <20150901220142.GA36428@cskk.homeip.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1.1441162045.8327.python-list@python.org> (permalink) |
On 02Sep2015 08:01, Cameron Simpson <cs@zip.com.au> wrote: >One circumstance where you might use fdopen and _not_ want .close to close the underlying service is when you're handed a file descriptor over which you're supposed to perform some I/O, and the I/O library functions use high level files. In that case you might want code like this: > > fd2 = os.dup(fd) > fp = open(fd2, 'a+b') # or whatever mode > ... do stuff, perhaps passing fp to a library function ... > fp.close() > >fd2 is not closed, but fd is still open for further use. Um, "fd2 _is_ closed". Whoops. Cheers, Cameron Simpson <cs@zip.com.au> Freedom is the right to be wrong, not the right to do wrong. - John G. Riefenbaker
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Low level file descriptors and high-level Python files Cameron Simpson <cs@zip.com.au> - 2015-09-02 12:08 +1000
csiph-web