|
本帖最后由 shaoheshaohe 于 2019-1-22 12:03 编辑
def circularFind(myByteArray, searchVal, start=0, end=len(myByteArray)):
""" Return the first-encountered index in bytearray where searchVal is found, searching to the right, in incrementing-index order, and wrapping over the top and back to the beginning if index end < index start """
if (end >= start):
return myByteArray.find(searchVal, start, end)
else:
#end < start, so search to highest index in bytearray, and then wrap around and search to "end" if nothing was found
index = myByteArray.find(searchVal, start, len(myByteArray))
if (index == -1):
#if searchVal not found yet, wrap around and keep searching
index = myByteArray.find(searchVal, 0, end)
return index
错误: NameError:未定义名称'myByteArray'
但是,如果我只删除我的默认参数(= 0和= len(myByteArray)),它可以正常工作。但是......我真的想要那些默认参数,以便start和end参数是可选的。我该怎么办?
修改:
def circularFind(myByteArray, searchVal, start=0, end=None):
""" Return the first-encountered index in bytearray where searchVal is found, searching to the right, in incrementing-index order, and wrapping over the top and back to the beginning if index end < index start """
if end is None:
end = len(myByteArray)
# continue doing what you were doing
|
|