how to open a dir which i just created in python few lines above(used current date and time to create the folder)?
Question:
datestring = datetime.datetime.now().strftime("%Y-%m-%d")
print(datestring)
os.mkdir(datestring)
(now i need to open this folder and create a csv file name as attendance)
f = open(datestring,’Attendance.csv’, ‘r+’)
writer = csv.writer(f)
Answers:
The simplest way is to use relative path to file. Also, I think you should use with
statement while operating with files.
datestring = datetime.datetime.now().strftime("%Y-%m-%d")
print(datestring)
os.mkdir(datestring)
with open(datestring + '/Attendance.csv', 'r+') as f:
writer = csv.writer(f)
# ... your further code ...
datestring = datetime.datetime.now().strftime("%Y-%m-%d")
print(datestring)
os.mkdir(datestring)
(now i need to open this folder and create a csv file name as attendance)
f = open(datestring,’Attendance.csv’, ‘r+’)
writer = csv.writer(f)
The simplest way is to use relative path to file. Also, I think you should use with
statement while operating with files.
datestring = datetime.datetime.now().strftime("%Y-%m-%d")
print(datestring)
os.mkdir(datestring)
with open(datestring + '/Attendance.csv', 'r+') as f:
writer = csv.writer(f)
# ... your further code ...