Python:当行包含字符串时,从pyodbc.row的结果集中过滤出行



我一直无法找到这个看似简单的过滤过程的答案。

我有一个简单odbc查询的表名结果集,我想过滤该结果集中包含前缀"wer_"的任何内容

*Some pyodbc connection code*
cursor.execute(<SQL statement which gets the list of tables>)
results = cursor.fetchall()
results = [key for key in results if str(key.name).str.contains('wer_')]

^我试过各种方法来解决这个问题,但到目前为止还没有成功。你能帮忙吗?

结果是相当直接的。pyodbc.row似乎有一个名称属性,你可以将其与进行比较

*Some pyodbc connection code*
cursor.execute(<SQL statement which gets the list of tables>)
results = cursor.fetchall()
results = [key for key in results if 'wer_' not in key.name]

我希望这对将来的某个人有所帮助!

最新更新