Forum Discussion

Amrendra's avatar
Amrendra
Occasional Contributor
7 years ago
Solved

I have a Excel name "CCP_MARGIN_2017-09-11_risk_cpm_stg.xlsx" in C drive. I am reading it and using

I have a Excel name "CCP_MARGIN_2017-09-11_risk_cpm_stg.xlsx" in C drive. I am successfully  reading it through excellib.excelRW('C:\temp\CCP_MARGIN_2017-09-11_risk_cpm_stg.xlsx').   The Problem i...
  • baxatob's avatar
    baxatob
    7 years ago

    CCP_MARGIN_2017-09-12_risk_cpm_stg.xlsx

     

    You have a string and one part of this string changes dynamically, right? 

     

    One way is to create a method which will return appropriate date:

     

    def get_file_name(date_):
        return "CCP_MARGIN_{}_risk_cpm_stg.xlsx".format(date_)

    Now if you call get_file_name("2017-09-13"), it returns: CCP_MARGIN_2017-09-13_risk_cpm_stg.xlsx

     

    You can hardcode the date argument or make it more flexible using Python's datetime library.

     

    For example you can set today's date:

     

    from datetime import date
    
    get_file_name(date.today())