小编Edw*_*ang的帖子

Python中的可变宽度Lookbehind问题

我有以下场景:

1) car on the right shoulder
2) car on the left shoulder
3) car on the shoulder
Run Code Online (Sandbox Code Playgroud)

当左边没有时,我想匹配"肩膀".所以只有3)回归"肩膀"

re.compile(r'(?<!right|right\s*)shoulder')
sre_constants.error: look-behind requires fixed-width pattern
Run Code Online (Sandbox Code Playgroud)

好像我不能用\ s*和"|"

我该怎么解决这个问题.

提前致谢!

python regex negative-lookahead lookbehind

10
推荐指数
1
解决办法
3761
查看次数

mongodb pymongo 当计数器 &gt; 1 时为空

我试图在 count() = 1 时做一些事情。我通过打印出来确认了 cursor.count() == 1,但是当我使用 cursor[0] 时,它引发了一个异常。

if not cursor.count():
    return self.create_new_incident(tweet)
elif loc_cur.count() == 1:
    return self.update_existing_incident(tweet, cursor[0])
....

File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 588, in __getitem__
    raise IndexError("no such item for Cursor instance")
Run Code Online (Sandbox Code Playgroud)

IndexError: Cursor 实例没有这样的项目

我读到: 使用 pymongo 的 ReplicaSetConnection:有时会收到“IndexError:光标没有这样的项目” 我已经关闭了其他未使用的连接,但仍然无法正常工作。

提前致谢

python cursor mongodb pymongo

1
推荐指数
1
解决办法
7483
查看次数