| Store | Cart

"print" as function not statement

From: Leif K-Brooks <eurl...@ecritters.biz>
Mon, 08 Mar 2004 07:32:00 GMT
Paul Prescod wrote:
>         As a convenience, if the show function is passed a>         single object to show, it returns that object. If>         it is passed more then one, it returns them as a>         tuple. This can be very convenient in debugging>         contexts.

That would lead to a problem with the interactive shell, though. For 
instance, this would happen:

 >>> show('foo')
foo
'foo'

I'm sure there would be some way around that, but it might add more 
oddities to the language than print does.

In any case, I did a quick Python implementation of the show function. 
All bugs are features. :-)

import sys

def show(*objects, **parameters):
     seperator = parameters.get('seperator', ' ')
     trailer = parameters.get('trailer', '\n')
     to = parameters.get('to', sys.stdout)
     first = 1
     for object in objects:
         if not first:
             to.write(str(seperator))
         to.write(str(object))
         first = 0
     to.write(str(trailer))
     if len(objects) == 1:
         return objects[0]
     else:
         return objects

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