Can't get the following python script to work with the date. import time from datetime import date from sys import argv script = argv filename = raw_input("filename?> ") today = date.today() print "Let's have some fun with %s." % script def to_do(day): s1 = "Brushed your teeth?> " s2 = "Applied acne medication?> " s3 = "Put ear lotion on?> " s4 = "Wrote double entry notes for huck finn?> " s5 = "Shot videos?> " l1 = raw_input(s1) l2 =raw_input(s2) l3 = raw_input(s3)
l4 = raw_input(s4) l5 = raw_input(s5) bar = "\n" txt= open(filename, 'a') format = l1, bar, l2, bar, l3, bar, l4, bar, l5, bar txt.seek(0,2) txt.writelines(format) txt.write(bar) txt.write(day) txt.close()
error = Traceback (most recent call last): File "C:\luis\Dropbox\programming\python\age1.py", line 27, in <module> to_do(today) File "C:\luis\Dropbox\programming\python\age1.py", line 25, in to_do txt.write(day) TypeError: must be string or read-only character buffer, not datetime.date
try adding string(day) before you call txt.write(day) to cast the date to a string. I think that write must only be able to take string types. http://stackoverflow.com/ is better for programming questions imho
It would help to see the code that calls to_do( day ) I don't see any code to convert the variable today to a string. I'm not familiar with the datetime object, but I'd bet it has a method to return a string of today's date.
Join our real-time social learning platform and learn together with your friends!