用法:
get_opcodes()
返回說明如何將
a
轉換為b
的 5 元組列表。每個元組的格式為(tag, i1, i2, j1, j2)
。第一個元組有i1 == j1 == 0
,其餘元組的i1
等於前一個元組的i2
,同樣,j1
等於前一個j2
。tag
值是字符串,具有以下含義:值
意義
'replace'
a[i1:i2]
應替換為b[j1:j2]
。'delete'
a[i1:i2]
應該被刪除。請注意,在這種情況下,j1 == j2
。'insert'
b[j1:j2]
應該插入到a[i1:i1]
。請注意,在這種情況下,i1 == i2
。'equal'
a[i1:i2] == b[j1:j2]
(sub-sequences 相等)。例如:
>>> a = "qabxcd" >>> b = "abycdf" >>> s = SequenceMatcher(None, a, b) >>> for tag, i1, i2, j1, j2 in s.get_opcodes(): ... print('{:7} a[{}:{}] --> b[{}:{}] {!r:>8} --> {!r}'.format( ... tag, i1, i2, j1, j2, a[i1:i2], b[j1:j2])) delete a[0:1] --> b[0:0] 'q' --> '' equal a[1:3] --> b[0:2] 'ab' --> 'ab' replace a[3:4] --> b[2:3] 'x' --> 'y' equal a[4:6] --> b[3:5] 'cd' --> 'cd' insert a[6:6] --> b[5:6] '' --> 'f'
相關用法
- Python difflib.SequenceMatcher.get_matching_blocks用法及代碼示例
- Python difflib.SequenceMatcher.find_longest_match用法及代碼示例
- Python difflib.unified_diff用法及代碼示例
- Python difflib.restore用法及代碼示例
- Python difflib.get_close_matches用法及代碼示例
- Python difflib.ndiff用法及代碼示例
- Python difflib.context_diff用法及代碼示例
- Python distributed.protocol.serialize.register_generic用法及代碼示例
- Python dict()用法及代碼示例
- Python distributed.Client.gather用法及代碼示例
- Python distributed.recreate_tasks.ReplayTaskClient.recreate_task_locally用法及代碼示例
- Python distributed.diagnostics.plugin.SchedulerPlugin用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.unregister_worker_plugin用法及代碼示例
- Python dictionary update()用法及代碼示例
- Python distributed.fire_and_forget用法及代碼示例
- Python dir用法及代碼示例
- Python distributed.Client.set_metadata用法及代碼示例
- Python distributed.Client.scheduler_info用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 difflib.SequenceMatcher.get_opcodes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。