Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'lines,': 0.05; 'subject:text': 0.05; 'converts': 0.07; 'parameter': 0.07; 'subject:file': 0.07; 'python': 0.09; 'lines:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'read.': 0.13; 'deprecate': 0.16; 'hint': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'iterators,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'string': 0.17; 'wrote:': 0.17; 'bytes': 0.17; 'jan': 0.18; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.28; 'no,': 0.29; 'objects': 0.29; 'subject: ?': 0.30; 'print': 0.32; 'to:addr:python-list': 0.33; 'adds': 0.35; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'here': 0.65; 'limit': 0.65; 'harder': 0.65; 'believe': 0.69; 'received:fios.verizon.net': 0.84; 'subject:write': 0.84; 'faster.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: print or write on a text file ? Date: Fri, 28 Sep 2012 20:41:38 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348879313 news.xs4all.nl 6886 [2001:888:2000:d::a6]:37363 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30441 On 9/28/2012 2:42 PM, Franck Ditter wrote: > Hi ! > Here is Python 3.3 > Is it better in any way to use print(x,x,x,file='out') > or out.write(x) ? Any reason to prefer any of them ? print converts objects to strings and adds separators and terminators. If you have a string s and want to output it as is, out.write(s) is perhaps faster. It is 6 chars shorted than print(s, file=out). > There should be a printlines, like readlines ? No, now that files are iterators, I believe readlines is somewhat obsolete. file.readlines() == list(file) The only reason not to deprecate it is for the hint parameter to limit the bytes read. That is little harder to do with the iterator. If you have any iterator of lines, for line in lines: line.print() is quite sufficient. There is little or no need for output limitation. -- Terry Jan Reedy