Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95850

Re: Low level file descriptors and high-level Python files

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'subject:file': 0.07; 'closed,': 0.09; 'descriptor': 0.09; 'subject:files': 0.09; 'underlying': 0.09; 'wrong,': 0.09; 'files.': 0.13; '.close': 0.16; 'fp.close()': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'stuff,': 0.16; 'wrote:': 0.16; 'library': 0.20; 'cheers,': 0.22; 'passing': 0.23; 'this:': 0.23; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'function': 0.28; 'i/o': 0.29; 'code': 0.30; 'supposed': 0.31; 'open': 0.33; 'file': 0.34; 'level': 0.35; 'but': 0.36; 'mode': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'whatever': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'some': 0.40; 'high': 0.60; 'close': 0.61; 'john': 0.61; 'further': 0.62; 'cameron': 0.66; 'received:61': 0.72
X-Authentication-Info Submitted using ID cskk@bigpond.com
X-Authority-Analysis v=2.0 cv=CsQ9gwED c=1 sm=1 a=6gXzooBB2Iv669Lo5MOndA==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=ff-B7xzCdYMA:10 a=ztR6jYicpZWHHgP2p_UA:9 a=CjuIK1q_8ugA:10 a=6gXzooBB2Iv669Lo5MOndA==:117
Date Wed, 2 Sep 2015 12:08:03 +1000
From Cameron Simpson <cs@zip.com.au>
To python-list@python.org
Subject Re: Low level file descriptors and high-level Python files
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <20150901220142.GA36428@cskk.homeip.net>
User-Agent Mutt/1.5.23 (2014-03-12)
References <20150901220142.GA36428@cskk.homeip.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1.1441162045.8327.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441162045 news.xs4all.nl 23733 [2001:888:2000:d::a6]:41972
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95850

Show key headers only | View raw


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


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