Q: Print whithout \n
Kalle Svensson
kalle at gnupung.net
Tue Dec 12 09:07:06 EST 2000
On Tue, 12 Dec 2000, Henrik Mårtensson wrote:
> How do you print a string whithout a linefeed in the end.
As others have said, print with a , works, but it gives you a space
instead. If this disturbs you as it does me, you can use the write method
of sys.stdout (or sys.stderr):
import sys
sys.stdout.write("Hej, ingen nyrad")
If you do something like
import sys
if filename:
outfile = open(filename, "w")
else:
outfile = sys.stdout
outfile.write("Whatever...")
outfile can be anything with a write method, which can be nice, e.g. for
handling different output formats.
Peace,
Kalle
--
Email: kalle at gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
Not signed due to logistical difficulties (I'm not at home).
If you doubt the authenticity of this message, please tell me.
More information about the Python-list
mailing list