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!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'interpreter': 0.04; 'lines,': 0.05; 'none,': 0.05; 'default.': 0.07; 'function,': 0.07; 'newline': 0.07; 'suppress': 0.07; 'trailing': 0.07; 'subject:question': 0.08; 'python': 0.09; '__future__': 0.09; 'assumed': 0.09; 'complaining': 0.09; 'interpreter,': 0.09; 'none.': 0.09; 'parameter.': 0.09; 'sep': 0.09; 'such.': 0.09; 'tuple': 0.09; 'windows,': 0.09; 'thread': 0.11; '"all"': 0.16; '"b"': 0.16; "'b'": 0.16; '``print``': 0.16; 'comma': 0.16; 'comma,': 0.16; 'comma.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'outputs': 0.16; 'stuff.': 0.16; 'wrote:': 0.17; 'odd': 0.17; 'string,': 0.17; '>>>': 0.18; 'input': 0.18; 'followed': 0.20; 'written': 0.20; 'import': 0.21; 'sorry,': 0.22; 'statement': 0.23; "i've": 0.23; 'second': 0.24; 'least': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'prevent': 0.27; "doesn't": 0.28; '>>>>': 0.29; 'end,': 0.29; 'lot.': 0.29; 'mode.': 0.29; 'prints': 0.29; 'received:192.168.1.3': 0.29; 'case,': 0.29; 'character': 0.29; 'probably': 0.29; "i'm": 0.29; 'usually': 0.30; 'ends': 0.30; 'keyword': 0.30; 'mode': 0.30; 'function': 0.30; 'file': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'done': 0.34; 'pm,': 0.35; 'too.': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'little': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'end': 0.40; 'first': 0.61; 'learned': 0.65; 'stuck': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; '(print': 0.84; 'explanation:': 0.84; 'newbie,': 0.84; 'posters,': 0.84; 'reply-to:addr:python.org': 0.84; 'angel': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=W6e6pGqk c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=lR6CHUT36vYA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=GDBcU3MMIQ8A:10 a=7ZGQ1RvyPqgA:10 a=les7gE2ZK8sA:10 a=ewxzYhnavgcA:10 a=r2bex4f3lfsA:10 a=sTOKQSFKWFoA:10 a=TFqcKDUXLT0A:10 a=RVSjMXkubmYA:10 a=haf4mBPXbV0A:10 a=03LxRvSYSnoA:10 a=O44_rB2XYmvUIDuijr4A:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Sun, 02 Sep 2012 23:43:42 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: newbie ``print`` question References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> In-Reply-To: <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346625829 news.xs4all.nl 6881 [2001:888:2000:d::a6]:36924 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28325 On 02/09/2012 21:58, gwhite wrote: > On Sep 2, 1:16 pm, Dave Angel wrote: >> On 09/02/2012 03:50 PM, gwhite wrote: >> >> >> >> >> >> >> >> >> >> > On Sep 2, 12:43 pm, Dave Angel wrote: >> >> On 09/02/2012 03:34 PM, gwhite wrote: >> >> >>> >> >>> btw, I also thought the default "add a CR LF" to the end was odd too. >> >>> But at least that one had a simple way out. >> >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. >> >> And even then, you can prevent it by using a 'b' in the mode. >> > Yes, I'm using windows. What is "'b' in the mode?" The help for >> > print says: >> >> > A ``'\n'`` character is written at the end, unless the ``print`` >> > statement ends with a comma. This is the only action if the statement >> > contains just the keyword ``print``. >> >> > So I followed with a comma to stop the default CR LF insertion. >> >> You're correct; the best way to suppress the newline at the end of >> print is to use the trailing comma. But since print is for lines, it >> usually is a good default. If you don't want to get any extra >> characters, just use write(). It takes a string, and outputs exactly >> what it's given. >> >> I assumed you were complaining about the conversion of newline to >> carriage-return-newline, which is done by default on Windows, and can be >> suppressed by opening the file with "b" as the mode parameter. > > > Sorry, I was a little vague on the newline stuff. > > In any case, I've learned I should probably avoid the comma, if > looking at 3.x: > >>>> from __future__ import print_function >>>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) > a=1.0, > (None,) > b=2.0 > Explanation: With 'print' as a function, the first 'print' prints the result of "'a=%.1f,' % 1.0" and then returns None. The trailing comma makes that into a tuple (None,), which is printed by the interactive interpreter as such. In other words: >>> None, (None,) >>> The second prints the result of "'b=%.1f' % 2.0" and then returns None. The interactive interpreter, recognising that it's only None, doesn't bother to print it. In other words: >>> None >>> > Given the input of several posters, I feel like I should probably be > using the `write` function anyway. (I don't have a problem pre- > constructing strings either.) > > But I am a newbie, and "all" the show-and-tell examples/tutorials use > `print`. But this little thread has helped me a lot. >