Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!ecngs!feeder2.ecngs.de!novso.com!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.05; 'subject:file': 0.07; 'python': 0.09; 'function:': 0.09; 'sep': 0.09; 'cc:addr:python-list': 0.10; 'appends': 0.16; 'did:': 0.16; 'experiment.': 0.16; 'newlines': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'leave': 0.26; 'values': 0.26; 'contrast,': 0.29; 'fri,': 0.30; 'subject: ?': 0.30; 'function': 0.30; 'print': 0.32; 'text': 0.34; 'there': 0.35; "i'll": 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'things': 0.38; 'end': 0.40; 'here': 0.65; 'from:addr:wayne': 0.84; 'subject:write': 0.84 Date: Fri, 28 Sep 2012 16:33:30 -0500 (CDT) From: Wayne Werner X-X-Sender: wayne@gilgamesh To: Franck Ditter Subject: Re: print or write on a text file ? In-Reply-To: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348868015 news.xs4all.nl 6929 [2001:888:2000:d::a6]:35628 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30429 On Fri, 28 Sep 2012, 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 ? > There should be a printlines, like readlines ? > Thanks, The print function automatically appends newlines to the end of what it prints. So if you had text = 'Hello!' and you did: print(text, file=outfile) then outfile would contain 'Hello!\n' In contrast, outfile.write(text) would only write 'Hello!'. No newline. There are lots of other handy things you can do with the print function: values = [1,2,3,4] print(*values, sep='\n', file=outfile) I'll leave it to you to experiment. HTH, Wayne