从生成器对象python返回值

时间:2020-04-27 10:09:28

标签: python

我有这段代码仅从字符串中提取数字:

infotype = (int(s) for s in chooseMappingStr.split() if s.isdigit())

如果我打印信息类型,它将返回一个生成器对象:

'<generator object dBQuery_foreignTable.<locals>.<genexpr> at 0x0000018A60CF33C0>'

是否可以从中返回int值?

1 个答案:

答案 0 :(得分:0)

只需放置[]而不是()

infotype = [int(s) for s in chooseMappingStr.split() if s.isdigit()]