How to write integers to a file?

Chris Gonnerman chris.gonnerman at
Fri Feb 9 14:39:13 CET 2001

outf.write("%d %d %d %d\n" % (i, j, k, l))

The % operator with a string on the left and a singleton value or tuple on
the right performs
printf-style substitution on the string.  You may need to read the man page
for printf if you are
not a C programmer.

----- Original Message -----
From: "Steven Sartorius" <ssartor at>
Newsgroups: comp.lang.python
To: <python-list at>
Sent: Friday, February 09, 2001 7:06 AM
Subject: How to write integers to a file?

> I'm trying to write a series of whitespace delimited integers to a file.
> The 'write' method only accepts strings and using arrays produces binary
> data when I open the file with less.  What I want is somehting like
> printf for python.  Is there any easy way to do this?  (there must
> be...this is python!)
> Any help much appreciated...
> Thanks,
> Steve Sartorius
> --

More information about the Python-list mailing list