且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中打开文件名+日期为csv

更新时间:2022-10-15 11:47:25

它应该看起来像这样:

  import datetime 
today_string = datetime.datetime.today ).strftime('%x')

with open('C:/ A / B / C / D / TODAYS SHEET'+ today_string +'.csv','w')as my_file:
my_file.write('a,a,a,a,a,a')

您可以查看字符串格式为strftime函数。另请查看打开功能以及您可以执行的操作使用文件


I want to be able to open a file name automatically and save it as a .csv, the files I produce are always called the same thing + todays date. For example todays spreadsheet could be called:

"TODAYS SHEET" + Todays date.xls

Stored in location

C:\A\B\C\D

How would I get the code to open todays .xls file and save it as a .csv in location

C:\A\B\C\D\E

I ultimately want to load data directly from this .csv file for comparison with a webscraper, so there may well be a method to open a .xls file as a .csv without saving it as a .csv in a second location.

It should look like something close to that:

import datetime
today_string = datetime.datetime.today().strftime('%x')

with open('C:/A/B/C/D/TODAYS SHEET' + today_string + '.csv', 'w') as my_file:
    my_file.write('a,a,a,a,a,a')

You can have a look at the string format for the strftime function. Also have a look at the open function and what you can do with files