Since you do not show your data or your output I cannot be sure. But it seems you are trying to use the write
method like the print
function, but there are important differences.
Most important, write
does not follow its written characters with any separator (like space by default for print
) or end (like \n
by default for print
).
Therefore there is no space between your data and steps number or between the lines because you did not write them and Python did not add them.
So add those. Try the lines
p.write(dte[x]) # Write date
p.write(' ') # space separator
p.write(str(stp[x])) # Write Steps number
p.write('\n') # line terminator
Note that I do not know the format of your "date" that is written, so you may need to convert that to text before writing it.
Now that I have the time, I'll implement @abarnert's suggestion (in a comment) and show you how to get the advantages of the print
function and still write to a file. Just use the file=
parameter in Python 3, or in Python 2 after executing the statement
from __future__ import print_function
Using print
you can do my four lines above in one line, since print
automatically adds the space separator and newline end:
print(dte[x], str(stp[x]), file=p)
This does assume that your date datum dte[x]
is to be printed as text.