Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'languages.': 0.04; 'exists.': 0.07; 'objects,': 0.09; 'oop': 0.09; 'descriptor': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'in-memory': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'open()': 0.16; 'roy': 0.16; 'why,': 0.16; 'wraps': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'library': 0.18; 'thu,': 0.19; 'command': 0.22; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'refers': 0.24; 'file.': 0.24; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'unix': 0.29; "doesn't": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'open': 0.33; 'objects': 0.35; 'there': 0.35; 'url:org': 0.36; 'example,': 0.37; 'so,': 0.37; 'clear': 0.37; 'skip:o 20': 0.38; 'sometimes': 0.38; 'initially': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'rather': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'is.': 0.60; 'skip:* 10': 0.61; 'further': 0.61; 'name': 0.63; 'such': 0.63; 'kept': 0.65; 'talking': 0.65; 'header:Reply-To:1': 0.67; 'smith': 0.68; 'reply-to:no real name:2**0': 0.71; 'article': 0.77; '"it': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:skip:o 10': 0.84; 'url:open': 0.95; '2013': 0.98 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=TZ6v63gh c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=GCTqkX7shA8A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=KPWSBcU8E6wA:10 a=RA7hJJdoAAAA:8 a=kZ7UWmmPAAAA:8 a=uZvujYp8AAAA:8 a=wonZCmQuU5CJBK2j0z8A:9 a=wPNLvfGTeEIA:10 a=wOeDSsudYCMA:10 a=pyH5b1fOeEsA:10 X-AUTH: mrabarnett:2500 Date: Thu, 09 May 2013 19:34:25 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: object.enable() anti-pattern References: <518a123c$0$11094$c3e8da3@news.astraweb.com> <518b32ef$0$11120$c3e8da3@news.astraweb.com> <518be931$0$29997$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <518be931$0$29997$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368124461 news.xs4all.nl 15921 [2001:888:2000:d::a6]:60765 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45053 On 09/05/2013 19:21, Steven D'Aprano wrote: > On Thu, 09 May 2013 09:07:42 -0400, Roy Smith wrote: > >> In article <518b32ef$0$11120$c3e8da3@news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> There is no sensible use-case for creating a file without opening it. >> >> Sure there is. Sometimes just creating the name in the file system is >> all you want to do. That's why, for example, the unix "touch" command >> exists. > > Since I neglected to make it clear above that I was still talking about > file objects, rather than files on disk, I take responsibility for this > misunderstanding. I thought that since I kept talking about file > *objects* and *constructors*, people would understand that I was talking > about in-memory objects rather than on-disk files. Mea culpa. > > So, let me rephrase that sentence, and hopefully clear up any further > misunderstandings. > > There is no sensible use-case for creating a file OBJECT unless it > initially wraps an open file pointer. > You might want to do this: f = File(path) if f.exists(): ... This would be an alternative to: if os.path.exists(path): ... > This principle doesn't just apply to OOP languages. The standard C I/O > library doesn't support creating a file descriptor unless it is a file > descriptor to an open file. open() has the semantics: > > "It shall create an open file description that refers to a file and a > file descriptor that refers to that open file description." > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html > > and there is no corresponding function to create a *closed* file > description. (Because such a thing would be pointless.) > [snip]