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)

Asked By: Siva Amir

||

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 ...
Answered By: Jurakin
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.