"print" as function not statement
Leif K-Brooks
eurleif at ecritters.biz
Mon Mar 8 02:32:00 EST 2004
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
More information about the Python-list
mailing list