Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'yet.': 0.04; 'argument': 0.05; 'f.close()': 0.09; 'function,': 0.09; 'file.read()': 0.16; 'foo()': 0.16; 'from:addr:greg.ewing': 0.16; 'from:name:greg ewing': 0.16; 'message-id:@canterbury.ac.nz': 0.16; 'received :conversion-daemon.it.canterbury.ac.nz': 0.16; 'valueerror': 0.16; 'wayne': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'passing': 0.19; 'input': 0.22; 'header:User-Agent:1': 0.23; 'greg': 0.24; 'certain': 0.27; 'enabled': 0.31; 'raised': 0.31; 'received:132': 0.31; 'class': 0.32; 'fri,': 0.33; 'done': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'received:nz': 0.60; "you're": 0.61; 'first': 0.61; 'happen': 0.63; 'invalid': 0.68; 'header:In-reply- to:1': 0.84; 'subject:skip:o 10': 0.84; '2013,': 0.91 Date: Mon, 13 May 2013 11:18:10 +1200 From: Greg Ewing Subject: Re: object.enable() anti-pattern In-reply-to: To: python-list@python.org MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) References: <518a123c$0$11094$c3e8da3@news.astraweb.com> 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368400703 news.xs4all.nl 15901 [2001:888:2000:d::a6]:47265 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45209 Wayne Werner wrote: > On Fri, 10 May 2013, Gregory Ewing wrote: > >> f = open("myfile.dat") >> f.close() >> data = f.read() > > To clarify - you don't want a class that has functions that need to be > called in a certain order with *valid input* in order to not crash. > > Exactly what does happen - a ValueError is raised because you're(*) > passing self into the file.read() function, and that input is invalid The same argument can be applied to: foo = Foo() foo.do_something() foo.enable() # should have done this first You're passing an invalid input to Foo.do_something, namely a Foo that hasn't been enabled yet. -- Greg