DateReading.write = (nowTimeDate2 + "\n") You're re-assigning the write method to be a string here. You want to call the method with the string as the argument.
DateReading.write(nowTimeDate2 + "\n") -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom....@python.org] On Behalf Of Steve Sent: Tuesday, February 12, 2019 2:20 PM To: python-list@python.org Subject: I cannot seem to write time/date to the file. I am using nowTimeDate2 elsewhere in my program and it can be printed to the screen. The file exists and the program successfully opens the file, writes to it, and closes the file. All is working as designed. However, Now I want to place an entry into the first line of the file to note the time/date the file was created. It doesn’t show up in the file. How do I fix this? from time import gmtime, strftime nowTimeDate2=strftime("%Y %a %b %d %H:%M") print(nowTimeDate2) #This works DateReading=open("Date-ReadingsAndDoses.txt", "w") DateReading.write = (nowTimeDate2 + "\n") DateReading.close() I also tried to append but that did not work either. Interestingly enough, this is a feature that really has no real purpose in the final product yet it is hounding me. Footnote: <http://click1.email.theonion.com/fdhhznrjhrcwhhsdwbqczwybqhwgsbrpzdlbfybhqbhhj_bjcgpjgcpypgjzzbfqdd.html?a=TheOnion_Daily_RSS&b=&c=> Ultrasound Technician Asks Pregnant Woman If She’d Like To Know Baby’s Name -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list