我在弄清楚如何找出这个文件模式时遇到了很多麻烦。我有以下代码:
def file_pattern_match(self, fundCode, startDate, endDate):
# check if the fundcode is in the array or if the fundcode matches one in the array
fundCode = fundCode if fundCode in self.fundCodes else 'Invalid_Fund_Code'
# set a file pattern
file_pattern = 'unmapped_{fund}_{start}_{end}.csv'.format(fund=fundCode, start=startDate, end=endDate)
# look in the unmappedDir and see if there's a file with that name
# if the there is load the positions
pass
这是一个作为类的一部分的函数。有一个问题。我刚刚意识到参数fundCode实际上是一个值数组,所以我需要使用某种分隔符。最后,我想寻找匹配这种模式的文件:
unmapped_FUND1_FUND2_FUNDETC_20180203_20180204.CSV或者
unmapped_FUND1_20180203_20180204.CSV
我猜正则表达式对此会很有用吗?