Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'represents': 0.05; 'subject:Python': 0.06; 'exists.': 0.07; 'expectation': 0.09; 'python': 0.11; '(file': 0.16; '23,': 0.16; 'closed.': 0.16; 'correspond.': 0.16; 'eckhardt': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'objects.': 0.16; 'represents.': 0.16; 'scope,': 0.16; 'subject:Query': 0.16; 'underlying': 0.16; 'world!")': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'thu,': 0.19; '>>>': 0.22; 'aug': 0.22; 'certainly': 0.24; 'header:In-Reply- To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; 'steven': 0.31; 'file': 0.32; 'run': 0.32; 'another': 0.32; 'open': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; '+0200,': 0.36; 'possible': 0.36; 'represent': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'affect': 0.61; 'side': 0.67; 'apart': 0.72; 'no:': 0.84; 'same,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=3Wh5OuM7AR3KVcquJ833vhILOkLe0S/xbiBneiejw3U=; b=fBMQis629enCfEYTRQ6Gi0rCwj2yDiJrDDkeP7ECqabhjN2XmTi0BueVTdZH2cEAnz EDQL1oPqmuC+cz66pLZJw4/HkZNeLvt6gzlgVdBEdT2e9VTdLXqu64EDRqJlBhdactBe 5jDutS7F3nxOzlTSMxVPTXZVjtnHCmx2huyX+iEChky1a3cyKt0DSSHxGHraHKCdhJrR aZnUQzgfZphebxtq++vFapCmhfR7C9eNz+um7CgHG+mjDBjoj8ts8Y3VMNeXle/0Mgi+ cI89nF6SVyfCCZGgszPfCw499AzteS1+a4yRNFuYAW2Tb2UfYKCiNiRVUkYokwHe6dOW rcRA== MIME-Version: 1.0 X-Received: by 10.52.72.195 with SMTP id f3mr104569vdv.59.1377273052038; Fri, 23 Aug 2013 08:50:52 -0700 (PDT) In-Reply-To: References: <6oahea-u2n.ln1@satorlaser.homedns.org> <5216d6cc$0$29986$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 24 Aug 2013 01:50:51 +1000 Subject: Re: Basic Python Query From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377273054 news.xs4all.nl 15867 [2001:888:2000:d::a6]:54535 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52897 On Fri, Aug 23, 2013 at 5:12 PM, Ulrich Eckhardt wrote: > Am 23.08.2013 05:28, schrieb Steven D'Aprano: >> >> On Thu, 22 Aug 2013 13:54:14 +0200, Ulrich Eckhardt wrote: >>> >>> When the Python object goes away, it doesn't necessarily affect >>> thethread or file it represents. >> >> >> That's certainly not true with file objects. When the file object goes >> out of scope, the underlying low-level file is closed. > > > Ahem, yes, but no: Calling close(fd) is not the same as destroying the file, > I'm pretty sure it's still on my harddisk after that. That is also the > difference to strings, where the Python object really is all there is to it. > Similarly you can only customize the Python side of things with derivation, > the other side will remain the same, apart from the data you write to the > file or the code you run in the thread. The file object doesn't represent the file on the disk; it represents the "open file", which is a thing that you can have a handle (file descriptor) to. That "thing" is indeed destroyed when the file object is __del__'d, though it's possible to dispose of it sooner than that: >>> f = open("test","w") >>> with f: f.write("Hello, world!") 13 >>> f <_io.TextIOWrapper name='test' mode='w' encoding='cp1252'> f has been closed at this point, and if I now go to open it in another application, Python won't hold any locks; but the object still exists. However, the general expectation is that the file object and the open-file in the OS will correspond. ChrisA