| Store | Cart

"print" as function not statement

From: David MacQuigg <d...@gain.com>
Wed, 10 Mar 2004 08:32:45 -0700
On 10 Mar 2004 05:43:22 -0500, aahz at pythoncraft.com (Aahz) wrote:

[snip]

>The other issue is that you're wrong to make print() a function.>Instead, it should be a callable object.  That way, the default print>object has state:>>    print(a, b, c)>    print.set_output(my_file)>    print(a, b, c)>    print(x, y, z)>    print.set_separator(None)>    print("The value is: ", 3)

This style will encourage users to separate the setting of non-default
behavior from the place where that behavior is used.  You won't know
by looking at a print statement what it is going to do.  For
situations like this, where we assume the default behavior (adding
spaces, for example) will only be over-ridden in a few places, I would
rather see the over-ride right where it is used.

show(5, 6, separator = ",")

If this needs to be done throughout the program, and typing the extra
argument gets to be annoying, then I would define a new function with
my intended default.

showWithComma(5, 6)

I would like to change the default behavior of the list class, but
Python (wisely) doesn't let me.  Instead I define a class
MyList(list), and add the methods I want.

-- Dave

Recent Messages in this Thread
Mark Kamikaze Hughes Mar 08, 2004 01:36 am
John Roth Mar 08, 2004 02:38 am
Leif K-Brooks Mar 08, 2004 07:32 am
Duncan Booth Mar 08, 2004 08:31 am
Leif K-Brooks Mar 08, 2004 10:36 am
A.M. Kuchling Mar 08, 2004 01:29 pm
Heather Coppersmith Mar 08, 2004 12:56 pm
David MacQuigg Mar 09, 2004 09:04 pm
Aahz Mar 10, 2004 10:43 am
Peter Otten Mar 10, 2004 12:52 pm
David MacQuigg Mar 10, 2004 03:32 pm
Messages in this thread
Previous post: Reading from stdin