no leading spaces in print

Skip Montanaro skip at mojam.com
Fri Aug 27 00:41:05 CEST 1999


    Matthew> I want to print, but I don't want the leading spaces
    Matthew> currently I am using 
    Matthew> print "whatever",
    Matthew> to have multiple print lines print on a single line

    Matthew> is there any way to fix this?

Sure.  Use sys.stdout.write instead:

    sys.stdout.write("whatever")
    sys.stdout.write("morespam")
    sys.stdout.write("fewereggs")
    sys.stdout.write("\n")

will emit

    whatevermorespamfewereggs

No unasked for spaces or newlines.  You are in total control.

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/~skip/
847-971-7098   | Python: Programming the way Guido indented...




More information about the Python-list mailing list