2014-12-04 74 views
1

我的影片返回以下值的SQL查询缓冲区 - 当我尝试这样做蟒蛇 - 类型错误:预期字符串或SQL查询

{'jobrun_deps': 'T=1 \x01ID=56494759 \x01DID=583887 \x01O=N \x01M=N \x01J=76732 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494760 \x01DID=418400 \x01O=N \x01M=N \x01J=48064 \x01R=14780471 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494761 \x01DID=583889 \x01O=N \x01M=N \x01J=76733 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01'} 

所以 -

results = (re.findall(r'ID=(\d+)', my_query)) 

我得到这个错误 -

Traceback (most recent call last): 
    File "D:\Scripts\OPS\TIDAL\dependency_check.py", line 25, in <module> 
    results = (re.findall(r'ID=(\d+)', my_query)) 
    File "D:\Python27\lib\re.py", line 177, in findall 
    return _compile(pattern, flags).findall(string) 
TypeError: expected string or buffer 

这是因为re.findall期望它在结果中没有列名。我该如何改变我的re.findall来使用我提供的输出或更改sql查询来提供一个字符串,就像它期望的那样。

'T=1 \x01ID=56494759 \x01DID=583887 \x01O=N \x01M=N \x01J=76732 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494760 \x01DID=418400 \x01O=N \x01M=N \x01J=48064 \x01R=14780471 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494761 \x01DID=583889 \x01O=N \x01M=N \x01J=76733 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01' 

回答

3

它,因为那是my_query一本字典,你不能把它传递给re.findall你需要把字典的值:

results = (re.findall(r'ID=(\d+)', my_query['jobrun_deps'])) 
+0

谢谢!知道这将是简单的事情。 – whoisearth 2014-12-04 22:04:44

+0

@whoisearth不客气! – Kasramvd 2014-12-04 22:05:10