printing with print

Corran Webster cwebster at math.tamu.edu
Tue Jun 29 16:43:25 EDT 1999


In article <377925EF.1CBB640F at starvision.com>,
Angus MacKay  <amackay at starvision.com> wrote:
>is there any other way to print that with print?
>perhaps with a real function.

Yes, use sys.stdout, which is a file object:

Python 1.5.2 (#13, Jun 16 1999, 23:19:35)  [GCC egcs-2.91.60 19981201 (egcs-1.1.1  on netbsd1
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> foo = "there"
>>> sys.stdout.write("Hi"); sys.stdout.write(foo);
Hithere>>>

Notice that it doesn't even put a newline in.  Also, you'll need to do
conversion to a string to get the result you want for foo = 2.

>>> sys.stdout.write("Hi"); sys.stdout.write(str(foo));
Hi2>>>

>foo = 2
>print "hi" + foo

You could do the explicit string conversion here too:

print "hi" + str(foo)

Corran





More information about the Python-list mailing list