now_date = str(datetime.datetime.now()) system = os.path.dirname(os.path.abspath(__file__)) new_now_date = system + '\\' + now_date.replace(' ', '-') + '.xlsx' save_workbook(excel, new_now_date) 

There is a table called "excel". I try to save it, the error takes off.

OSError: [Errno 22] Invalid argument: 'C:\\Users\\Professional\\Desktop\\Парсер hh.ru\\2019-02-08-22:14:26.562539.xlsx'

  • one
    Colon in Windows seems to be banned? - andreymal

1 answer 1

Because : requested sign in the final name 2019-02-08-22:14:26.562539.xlsx .

Replace the colon for example with a period:

 new_now_date = system + '\\' + now_date.replace(' ', '-').replace(':', '.') + '.xlsx' 

Note:

It is more beautiful and safer to use os.path also connect the path and file name:

 new_now_date = os.path.join(system, now_date.replace(' ', '-').replace(':', '.') + '.xlsx')