Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'syntax': 0.04; '*not*': 0.07; 'cleanup': 0.09; 'f.close()': 0.09; 'messing': 0.09; 'statements': 0.09; 'api': 0.11; 'cc:addr:python- list': 0.11; 'python': 0.11; '2.7': 0.14; 'anyways,': 0.16; 'cleaner': 0.16; 'exist.': 0.16; 'statement.': 0.16; 'underlying': 0.16; 'url:whatsnew': 0.16; 'wayne': 0.16; 'appropriate': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'properly': 0.19; 'thu,': 0.19; 'seems': 0.21; 'preferred': 0.22; 'cc:addr:python.org': 0.22; 'greg': 0.24; "shouldn't": 0.24; 'url:dev': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'least': 0.26; 'certain': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'errors': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'file': 0.32; 'class': 0.32; 'skip:m 30': 0.32; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'implement': 0.38; 'skip:o 20': 0.38; 'requiring': 0.38; 'needed': 0.38; 'pm,': 0.38; 'bad': 0.39; 'called': 0.40; 'url:mail': 0.40; 'up,': 0.60; 'simply': 0.61; 'information': 0.63; 'chance': 0.65; 'due': 0.66; 'remembering': 0.84; 'subject:skip:o 10': 0.84; 'reasoning': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=yE9d4nbMS2Sv8zZPKscAQi+N7AQf/P7XcdIxhE3PdQ8=; b=pt7vw0h/cxlCrNJjN+l3RkzLnmA9Yujpv722NRN/socttYdYVeYZc4sFfQcfgmJq11 dnhfCGeQD0t4cHZHep2ya//DErSeHN34vylvqXujh3Fx5xVDzA9uaveqyhBijxtca0Wd NOaiOlw41vSMrvJwXQdiPexfNxuPn1rUTQFELRuwJ4GHZy2fmVsWWcymHqo157zPb4WP nbskr+Ccz2s/gk4AFRZ8G9WIF6JMNKaDwXBEvG+G3vEbtRfv9c7qkIa9vrCLSFWroLG/ G2/uczK9vqj45cabhWO4Yo4Ti+VS2s0klQdO/V9SrwTplpTJ2oiCzCOOK+D8qXGP5TOK qQdw== MIME-Version: 1.0 X-Received: by 10.220.82.68 with SMTP id a4mr9454475vcl.49.1368145119858; Thu, 09 May 2013 17:18:39 -0700 (PDT) Sender: knome.net@gmail.com In-Reply-To: References: <518a123c$0$11094$c3e8da3@news.astraweb.com> Date: Thu, 9 May 2013 20:18:39 -0400 X-Google-Sender-Auth: gLm4jcypYy0RbDJRYVNwZyPo2zo Subject: Re: object.enable() anti-pattern From: Michael Speer To: Gregory Ewing Content-Type: multipart/alternative; boundary=001a11c1e23aded56704dc521b68 Cc: python-list@python.org 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: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368145123 news.xs4all.nl 15865 [2001:888:2000:d::a6]:35544 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45070 --001a11c1e23aded56704dc521b68 Content-Type: text/plain; charset=ISO-8859-1 By his reasoning it simply shouldn't exist. Instead you would access the information only like this: with open("myfile.dat") as f: data = f.read() Which is my preferred way to work with resources requiring cleanup in python anyways, as it ensures I have the least chance of messing things up, and that all of my resources are disposed of properly during the unwind. It's a hell of a lot cleaner than remembering to call the appropriate cleanup functions at every callsite, and the resultant values can never be in a bad state ( at least due to programmer function-ordering fault, underlying file i/o errors and things can still cause errors, but not due to API mis-usage ). Python 3's multiple-with-statement-target syntax was backported to 2.7 as well, flattening the deep nests of with statements otherwise needed to implement this pattern http://docs.python.org/dev/whatsnew/2.7.html#other-language-changes On Thu, May 9, 2013 at 7:43 PM, Gregory Ewing wrote: > Wayne Werner wrote: > >> You don't ever want a class that has functions that need to be called in >> a certain order to *not* crash. >> > > That seems like an overly broad statement. What > do you think the following should do? > > f = open("myfile.dat") > f.close() > data = f.read() > > > -- > Greg > -- > http://mail.python.org/**mailman/listinfo/python-list > --001a11c1e23aded56704dc521b68 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
By his reasoning it simply shouldn't exist. Instead yo= u would access the information only like this:

with = open("myfile.dat") as f:
=A0 data =3D f.read()

Which is my preferred way to work with= resources requiring cleanup in python anyways, as it ensures I have the le= ast chance of messing things up, and that all of my resources are disposed = of properly during the unwind. It's a hell of a lot cleaner than rememb= ering to call the appropriate cleanup functions at every callsite, and the = resultant values can never be in a bad state ( at least due to programmer f= unction-ordering fault, underlying file i/o errors and things can still cau= se errors, but not due to API mis-usage ).

Pytho= n 3's multiple-with-statement-target syntax was backported to 2.7 as we= ll, flattening the deep nests of with statements otherwise needed to implem= ent this pattern

On Thu, May 9, 2013 at 7:43 PM, Gregory Ewing <greg.ewing@canter= bury.ac.nz> wrote:
Wayne Werner wrote:
You don't ever want a class that has functions that need to be called i= n a certain order to *not* crash.

That seems like an overly broad statement. What
do you think the following should do?

=A0 =A0f =3D open("myfile.dat")
=A0 =A0f.close()
=A0 =A0data =3D f.read()

--001a11c1e23aded56704dc521b68--