[Tutor] print command

Alan Gauld alan.gauld at freenet.co.uk
Mon Mar 21 21:07:39 CET 2005


> You can get full control of the output by using sys.stdout.write()
instead of print. Note the
> arguments to write() must be strings:
>
> import sys
> sys.stdout.write(str(1))
> sys.stdout.write(str(2))
> sys.stdout.write(str(3))
> sys.stdout.write('\n')
>
> Or you can accumulate the values into a list and print the list as
Lutz has suggested:

Or for an easier technique than join/split, use a print format string:

> l = []
> l.append(1)
> l.append(2)
> l.append(3)

fmtString = "%s" * len(l)
print fmtString % tuple(l)

HTH,

Alan G.



More information about the Tutor mailing list