python regex中的变量?在气流中打印报表?

2024-06-16 08:24:43 发布

您现在位置:Python中文网/ 问答频道 /正文

如果存在一个简单的.txt-04目录,请参阅“我在使用一个简单的.txt-04目录下的程序。我有两个问题。在

A)我想在正则表达式中使用变量datestr。不知道该怎么做。在

B)其次,我的打印(文件名)在airflow UI中显示在哪里?我查了查看日志,但什么也没显示出来。在

def checksFile():   
        d = datetime.today()-timedelta(days=1)
        datestr = '{:%Y-%m-%d}'.format(d)
        for filename in os.listdir('/mnt/volume/home/aabraham/'):
            match = re.search('(test)-(2018-06-04)-(\d+)(\.txt)', filename)
            print(filename)
        if not match:
            raise AirflowException("File not Found")

Tags: 程序目录txtuitodaydatetime文件名def
2条回答

不能以控制台中相同的方式使用print。在

要查看Log页面中的日志条目,请使用logging.info。也许你需要import logging。在

要回答regex问题,只需将字符串添加到一起:

match = re.search('(test)-(' + datestr + ')-(\d+)(\.txt)', filename)

只有当datestr不包含任何regex文本时,这才有效。在

相关问题 更多 >