![]() ![]() ![]() Globbed_list = #extended list with each possible date format comboĮxtended_base_filename_list = [f.replace("DATE", d) for f in base_filename_list # list of possible save_as_of date formatsĭate = datetime.strptime(saved_as_of, '%Y-%m-%d') I think pathlib glob only accepts str, not a list if i interpreted your answer correctly. not sure how to use the format function the way you intended. Thank you for the pointers, here is all I could master. The code above will get you 90% of the way there, but I'll leave that as an exercise for you to complete. For instance: from pathlib import Pathĭef get_path_list(directory, base_filename_list, saved_as_of): Also, it's kind of expected :-)Īs to the core questions you have, you can use pathlib's Path object to assist with the globbing of files and matching file parameters, as well as the string formatting format function to replace "placeholders" with a certain value. As an example, if you don't have this, when you use tools like Sphinx to produce code documentation, it will actually run your code instead of just building the objects. Your code lacks a if _name_ = "_main_": starting section. ![]() If you're going to write python, PEP8 states snake_case should be used as the expected style. Your code uses a mixture of snake_case and camelCase, you should stick to a specific style.Print (len(get_path_list(folderMarket, files_market, strToday))) Path_list.append(os.path.join(directory, filename)) StrDate2 = datetime.strptime(savedAsOf, '%Y-%m-%d').strftime('%d%b%y')įilename_list2 = įilename_list = filename_list1 + filename_list2 is there a better way to build a filename_list instead of brute force used below? from datetime import datetimeįiles_market = ĭef get_path_list(directory, base_filename_list, savedAsOf):įilename_list1 = My helper function is tasked with extracting a path list matching each found file name against filename_list. The date tag can be formatted differently, e.g. My directory folderMarket has lots of files with the same name but are tagged with a date string at the end. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |