python - python 正则表达式中的变量?在 Airflow 中打印报表?

标签 python regex airflow

我正在开发一个简单的程序,以使用 Airflow 查看目录中是否存在文件“test-2018-06-04-1358.txt”。我有两个问题。

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")

最佳答案

要回答正则表达式问题,只需将字符串添加在一起即可:

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

只有当 datestr 不包含任何正则表达式文字时,这才有效。

关于python - python 正则表达式中的变量?在 Airflow 中打印报表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723581/

相关文章:

python - 我可以在 python 中使用字符串作为命名参数吗

python - 重复游戏 - Python 石头、剪刀、布

javascript - 如何正则表达式方括号?

apache-spark - Spark 提交给YARN时出现 “unknown queue: root.default”错误

python - 检查广播变量 PySpark 的大小

python - python中的数据格式二进制模式描述和解码

ruby - 如何使用要在倒排索引中使用的正则表达式匹配 Ruby 中的多行字符串?

java - 正则表达式获取2位数字,数字不立即在Java字符之前和之后

airflow - 如何通过 REST API 触发 Airflow DAG?

airflow - 为什么不建议在 Airflow 中使用动态 start_date?