簡體   English   中英

成對不使用 itertools 導入

[英]Pairwise not being imported with itertools

我在 python 3.8.2 上,我嘗試了以下代碼

from itertools import pairwise

但是,它返回

ImportError: cannot import name 'pairwise' from 'itertools' (unknown location)

我嘗試了相同事物的其他變體,例如import itertools itertools.pairwise ,但它仍然給我錯誤。

我認為這可能是拼寫錯誤所以我嘗試了

from itertools import *

print(dir())

但它不在那里

['__builtins__', '__file__', '__name__', '__warningregistry__', 'accumulate', 'chain', 'combinations', 'combinations_with_replacement', 'compress', 'count', 'cycle', 'dropwhile', 'filterfalse', 'groupby', 'islice', 'permutations', 'product', 'repeat', 'starmap', 'takewhile', 'tee', 'zip_longest']

我什至在不同的設備和在線翻譯器上嘗試過。 在線翻譯的截圖,因為這聽起來很瘋狂

這種成對僅隨 Python 3.10+ 一起提供。 在之前的版本中,它列在Itertools Recipes部分下。

這就是為什么你找不到它。 嘗試始終升級到最新版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM