Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: print with no newline

Reply
Thread Tools

RE: print with no newline

 
 
Tim Golden
Guest
Posts: n/a
 
      09-03-2004
[Jp Calderone]
| Basically, print is only meant to help people new to the
| language get started
| It often does what will make life easiest for someone who is
| just getting into things, but which is otherwise confusing, expected,
| special-casey, or otherwise undesirable. I mean, the whole
| existence of the keyword "print" is an inconsistency, right?
| One could quite reasonably expect print to be a function.

This point of view comes up from time to time on the list
and for the life of me I can't buy into it. Putting aside
the obviously tongue-in-cheek implication that only beginners
would use print, I have almost never found print to be
"confusing... or otherwise undesirable". It does exactly
what I expect it to do with the minimum of syntactic clutter.

If I want something which I consider special-casey, for example
output with no newline, then I know what my options are. And
for the most part that'll be when I'm writing out to a file,
in which case I'm almost certainly using the f.write etc.
methods of the file object.

I would *not* reasonably expect print to be a function. Why
should it be? Certainly any move to remove the print statement
from the language or to replace it by a print function would
get my thumbs-down (or whichever way round the Romans did it).

TJG

__________________________________________________ ______________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
__________________________________________________ ______________________
 
Reply With Quote
 
 
 
 
Istvan Albert
Guest
Posts: n/a
 
      09-03-2004
Tim Golden wrote:

> This point of view comes up from time to time on the list
> and for the life of me I can't buy into it. Putting aside
> the obviously tongue-in-cheek implication that only beginners
> would use print, I have almost never found print to be
> "confusing... or otherwise undesirable". It does exactly
> what I expect it to do with the minimum of syntactic clutter.


My feelings exactly. There's nothing wrong with
print. Leave it alone or else.

For those who want full control use the write
method of the object you are writing to.
It is not complicated.

Istvan.
 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      09-04-2004
Tim Golden <(E-Mail Removed)> wrote:
...
> I would *not* reasonably expect print to be a function. Why
> should it be?


Because the concept of print being a statement it has no true advantage,
and several disadvantages, compared with the obvious alternative of it
being a built-in function. 'print' becomes a keyword, which is always a
cost -- try accessing a member named 'print' in any kind of ffi or
distributed-programming interface (be it COM, Corba, xml/rpc, whatever)
and you'll see why minimizing reserved words is a great thing... try
making a dict with the string 'print' as a key and suddely you can't use
the cool syntax dict(akey=23) and have to quote... you can't use print
in a lambda nor any other expression, you can't pass print to a higher
order function requiring a callable, you can't store it in a list of
dict -- all wonderful things you can do with functions but not with
statements.

Hoping that you can see there ARE disadvantages in having print be a
statement, let's look for advantages. The ability to not use
parentheses isn't really one -- parentheses are nice, they let you just
break long lines as needed for example. If lack of parentheses WERE
important, Python would support "foo bar" meaning foo(bar), but it
doesn't. What else? The mysterious end-with-a-comma syntax to remove
the default newline? Teaching that to beginners is a chore, while a
function would have a keyword argument such as endline=True, and passing
endline=False would suppress the end-line. Instead of the horrid >>file
syntax we'd have file=sys.stdin. And if the BDFL ever decides some
other optional nondefault behavior is warranted, having keyword args
would make expressing it a snap, while, with print as a statement, it's
a huge problem.

I hope you see now why many of us hard-boiled Pythonistas dislike print
being a statement and consider it a wart in Python.


> Certainly any move to remove the print statement
> from the language or to replace it by a print function would
> get my thumbs-down (or whichever way round the Romans did it).


We'll fight that batte at Python 3.0 time, then. And I'm giving some of
my side's ammunition away, tch...!-) What heartens me is that it's not
only the usual suspects -- experts who typically teach Python to other
experienced programmers, not to total newbies -- who agree with me on
this; I have an ally on this specific subject who's among the paladins
of NON-programmers... my wife, Anna (her background is primarily in
training -- she started programming relatively recently, and with Python
as her first language discounting the modest Basic and Pascal exposure
she got back in high school).

While the BDFL is typically not really swayed by argument -- what does
help him make up his mind is one of life's mysteries... -- he doesn't
discount argument 100%, so you guys liking print as a statement should
eventually start preparing your own arguments (no hurry, Python 3.0
won't happen for years yet). They don't have to be quite as powerful as
those for print being a builtin function (they can't -- print being a
builtin function is RIGHT, it being a statement is WRONG, so obviously
the arguments for the former stance are inherently more powerful than
those for the latter!-) but they need to be decent enough to help Guido
rationalize what his nose suggests ot him, should that suggestion lean
towards keeping print a statement...!-)


Alex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print with no newline Paul Watson Python 9 09-04-2004 08:07 PM
How to I print without newline ? fowlertrainer@anonym.hu Python 4 05-28-2004 02:24 PM
Re: How to I print without newline ? Ray Cote Python 1 05-27-2004 05:05 PM
RE: How to I print without newline ? David Stockwell Python 0 05-27-2004 03:54 PM
Print always puts newline (or adds a space) Tobiah Python 5 09-16-2003 07:43 PM



Advertisments