My goal is to write a script which will once I run it write the current Unix timestamp to a file. I tried several scripts which show the Unix timestamp directly such as this:
import time
print time.time()
While searching for an answer I came across a script which will write the current date and time with the datetime module to a file:
import datetime
f=open("/home/user/file.txt",'a')
f.write(datetime.datetime.now().ctime())
So I thought that if it's possible to write it with
(datetime.datetime.now().ctime()
, the same would be possible with for example:
import time
f=open("/home/user/file.txt",'a')
f.write(time.time())
Unfortunately I got this same error every time I tried something similar:TypeError: expected a string or other character buffer object
. I've tried fixing this, but I couldn't so far. Any help or recommendation is greately appreciated.