问题描述
我想要能够自动打开文件名并将其保存为.csv文件,我生成的文件总是被称为同一事物+今天的日期。例如,今天的电子表格可以调用:
TODAYS SHEET+今天date.xls
存储在位置
C: \\ A \B \C\D
如何让代码在今天打开。 xls文件并将其另存为.csv位置
C:\A\B\C\D\\ \\ e
我最终希望直接从此.csv文件加载数据,以便与webscraper进行比较,因此可能有一种方法可以将.xls文件打开为.csv格式,而不将其另存为.csv格式。
解决方案它应该看起来像这样:
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')
您可以查看以及您可以执行的操作
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
这篇关于在Python中打开文件名+日期为csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!