Home > Software design >  how to open a dir which i just created in python few lines above(used current date and time to creat
how to open a dir which i just created in python few lines above(used current date and time to creat

Time:11-05

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)

CodePudding user response:

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 ...
  • Related