Am wanting to attach the date to the name of a text file that gets generated as a result of a whole heap of user inputs.
What I have done is save the name of the file as a variable called name. When I do this everything runs fine and I don't have any issues.
However when I try to attach a date (saved as a string) it comes up with this
Traceback (most recent call last):
File "datalogger.py", line 165, in <module>
f = open(name + ".txt", "w")
IOError: [Errno 2] No such file or directory: 'new23/8/2012.txt'
This is how I get the date
from datetime import datetime now = datetime.now() current_year = now.year current_month = now.month current_day = now.day date = str(now.day) + "/" + str(now.month) + "/" + str(now.year)
this is how I get the file name and add the variable date to it
name = raw_input("What would you like to name yoru file ?: \n")
name = name + str(date)
and this is how I'm writing the file
f = open(name + ".txt", "w") f.write(users inputs here)
When I just keep the name as the user defines all works fine but when I add the variable date to it the file wont write.
Any help is appreciated
Cheers
Aaron

New Topic/Question
Reply



MultiQuote



|