Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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; '16,': 0.03; 'else:': 0.03; 'subject:Python': 0.06; '*is*': 0.09; 'append': 0.09; 'bytes,': 0.09; 'expense': 0.09; 'slow.': 0.09; 'uses.': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'file-like': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mode,': 0.16; 'reasonably': 0.16; 'subclass': 0.16; 'write,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'file,': 0.19; 'cc:addr:python.org': 0.22; 'print': 0.22; 'fairly': 0.24; 'file.': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'quite': 0.32; 'open': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'right?': 0.36; 'easily': 0.37; 'being': 0.38; 'problems': 0.38; 'pm,': 0.38; 'either': 0.39; 'skip:p 20': 0.39; 'different': 0.65; 'talking': 0.65; 'close': 0.67; 'risk': 0.72; 'jul': 0.74; 'attractive': 0.81; 'potentially': 0.81; 'actually,': 0.84; 'avoids': 0.84; "it'd": 0.84; 'to:none': 0.92; 'imagine': 0.93 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:cc :content-type; bh=3G2m5YHo6fBcdtS/dLZ3HM3zFguIboDZ52XIOFWsceM=; b=CBFtMnFYI4A8OPjeMp5kLHpemwPB/jKMRdHOM5+qw/SvvkervUOb4XQgqWR7qTcX+j E7SgNuA5r5a4rjm8xsbaykvJi4WigwNaJKxNRk4fAgEJ1WZeTCoIFldb+oJc+l8vh014 EXso6JIhuwhk9RCquuxZroQ+cdfkf4ZIWVlMqY9taY1xkp9v8M6hOisWQyJXhde1QA93 l3WB3O71OLxnJuaH1cq9Gkq4Bjsbqati3GwSRoXd7EebK/Fs5pMw0veF2RLf1t7M6acI AzyIBdwD2EEX5Zto4ite6s2CHe1g9oEXpfaQSmK/Z9gfSnIekN6YoNoXmQPbPrMNYOLl p3gQ== MIME-Version: 1.0 X-Received: by 10.220.80.70 with SMTP id s6mr7048532vck.44.1405511662005; Wed, 16 Jul 2014 04:54:22 -0700 (PDT) In-Reply-To: <53c6638b$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> <99b7b2a2-7521-42d7-a5a0-1a35d4d5b922@googlegroups.com> <53C4A454.9010600@gmail.com> <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c62e7f$0$29897$c3e8da3$5496439d@news.astraweb.com> <53c6638b$0$9505$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 16 Jul 2014 21:54:21 +1000 Subject: Re: Python 3 is killing Python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405511663 news.xs4all.nl 2830 [2001:888:2000:d::a6]:35893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74548 On Wed, Jul 16, 2014 at 9:35 PM, Steven D'Aprano wrote: > What I had in mind was for print to open the file in append mode, write, > then close the file. Ahh, okay. Very different from what I thought you were talking about, and distinctly different in behaviour from REXX :) In that case, it avoids the problems that I described, at the expense of being potentially an attractive nuisance - imagine code like this: for line in open("input.txt"): print(transform(line), file="output.txt") Looks like a really nice clean way to process a file, right? But it's going to be horrendously slow. Actually, this could be quite reasonably added as a feature of print(). Could be monkey-patched in fairly easily _origprint = print def print(*a, **kw): if isinstance(kw.get("file"), (str, bytes)): with open(kw["file"], 'a') as f: kw["file"] = f _origprint(*a, **kw) else: _origprint(*a, **kw) And it'd have its uses. The only risk would be if there's a file-like object that's a subclass of either str or bytes, which admittedly *is* theoretically possible... ChrisA