Reputation: 3
My apologies if this has been answered - I suspect it's very simple - but I can't see how to do it.
It's easier to demonstrate what I want to do.
vflag=True
def printv(*prargs):
if vflag:
print prargs
# print *prargs gives a syntax error, unsurprisingly
printv("hello", "there", "world")
printv("hello", "again")
I want the output to be
hello there world
hello again
and I get (of course)
('hello', 'there', 'world')
('hello', 'again')
Upvotes: 0
Views: 49
Reputation: 32189
You should do it as:
def printv(*prargs):
if vflag:
print ' '.join(prargs)
>>> printv("hello", "there", "world")
hello there world
The string.join(iterable)
returns a string of all the elements in the list separated by the specified string, in this case ' '
(a whitespace).
Upvotes: 1