0

I am trying to create a blank file with current data time in python on certail location. the code is

 from datetime import datetime

# datetime object containing current date and time
now = datetime.now()
 
print("now =", now)

# dd/mm/YY H:M:S
extension = ".txt"
dt_string = now.strftime("%d-%m-%Y %H-%M-%S")
# print("date and time =", dt_string)   
folder=r"C:\Users\deepankar.srigyan\Desktop\Data Science Project\Log_test"

filename= (folder+"\\"+dt_string + extension)
file = open(file_name, 'w')
file.close()

Now I am getting following error, can some one help me with this:

   ---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-67-a9093bada33c> in <module>
     13 
     14 filename= (folder+"\\"+dt_string + extension)
---> 15 file = open(file_name, 'w')
     16 file.close()
     17 

OSError: [Errno 22] Invalid argument: 'C:\\Users\\deepankar.srigyan\\Desktop\\Data Science Project\\Log_test\\2021-04-13 14:49:32.927857.txt'

0 Answers0