RE: print with no newline

Discussion in 'Python' started by Tim Golden, Sep 3, 2004.

  1. Tim Golden

    Tim Golden Guest

    [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
    ________________________________________________________________________
     
    Tim Golden, Sep 3, 2004
    #1
    1. Advertising

  2. 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.
     
    Istvan Albert, Sep 3, 2004
    #2
    1. Advertising

  3. Tim Golden <> 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
     
    Alex Martelli, Sep 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tobiah
    Replies:
    5
    Views:
    340
    Erik Max Francis
    Sep 16, 2003
  2. Replies:
    4
    Views:
    583
    Chris Herborth
    May 28, 2004
  3. David Stockwell

    RE: How to I print without newline ?

    David Stockwell, May 27, 2004, in forum: Python
    Replies:
    0
    Views:
    3,499
    David Stockwell
    May 27, 2004
  4. keto
    Replies:
    0
    Views:
    1,043
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    399
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page