On 2019-08-10 09:10:12 +1000, Cameron Simpson wrote: > On 09Aug2019 22:28, Paul St George <[email protected]> wrote: > > On 09/08/2019 16:29, Rhodri James wrote: > > > (Actually I would probably use outstream.write() and do my own > > > formatting, but let's not get side-tracked ;-) > > > > > I would love to hear your outstream.write() side-track! > > I am not Rhodri James, but you can just write strings to text files: > > outstream.write("X: ") # note, includes the space separator > outstream.write(str(thing[0])) > outstring.write("\n")
You can also format the string before passing it to write (which is
probably what Rhodri meant by "do my own formatting", like this:
outstream.write("X: %7.2f\n" % thing[0])
or this
outstream.write("X: {0:7.2f}\n".format(thing[0]))
or (since Python 3.6) this:
outstream.write(f"X: {thing[0]:7.2f}\n")
There are of course many variants to all three methods.
hp
--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | [email protected] | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list
