print - parameters ?

Alex Martelli aleaxit at yahoo.com
Tue Oct 5 05:13:08 EDT 2004


Helmut Jarausch <jarausch at igpm.rwth-aachen.de> wrote:

> Hi,
> sorry for this probably very simple question.
> 
> How can I build a parameter list for 'print' ?

You can't really do that, since (alas) it's a statement, not a function.

> Background:
> I'd like to write a function like
> 
> def myprint(Msg,*Args) :
>    print (Msg,)+Args

def myprint(Msg, *Args):
    print Msg,
    for arg in Args: print arg,
    print

> myprint('this is',x)
> 
> gives
> 
> ('this is', <__main__.ABC instance at 0x4084fc8c>)
> 
> instead of
> 
> this is ABC-class

You're printing a tuple, and that uses repr on each item, with commas to
separate and parentheses around it all.


> What am I missing (what sort of thing is the parameter list of print) ?

It's not really a "sort of thing", alas... print is a statement so it
lives by its own rules (a Python wart, Guido's admitted that; maybe it
will change in Python 3000... let's hope!).


Alex



More information about the Python-list mailing list