- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个继承自collections.Counter
的Python类:
class Analyzer(collections.Counter):
pass
当我在这段代码上使用 pylint 时,它的答案是:
W: Method 'fromkeys' is abstract in class 'Counter' but is not overridden (abstract-method)
我在我的机器上检查了 collections.Counter
的实现,实际上,这个方法没有实现(注释有助于理解原因):
class Counter(dict):
...
@classmethod
def fromkeys(cls, iterable, v=None):
# There is no equivalent method for counters because setting v=1
# means that no element can have a count greater than one.
raise NotImplementedError(
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
但是,我真的不知道如何实现这个方法,如果 Counter
本身没有......
在这种情况下如何解决这个警告?
最佳答案
This question应该在这里回答一些问题。基本上,pylint 检查引发的 NotImplementedError
异常,以确定方法是否是抽象的(在本例中为误报)。添加注释 #pylint:disable=W0223
将禁用此检查。
this question中也提出了类似的问题.
关于python - 从集合继承。计数器: 'fromkeys' is abstract,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44544806/
我已将以下 xml 属性存储到 HashMap extraParams = new HashMap() 基本上我想在 kets sourceAttrStart 之间获取 hashmap 的
本文实例讲述了python使用dict.fromkeys()快速生成一个字典。分享给大家供大家参考,具体如下: ?
我需要将 test_input 中的数据与 classes 进行分组,即,如果 test_input 中的 2 个值相同,则它们应该具有相同的类. 我尝试创建一个字典,但不知道如何进行类管理: @py
我尝试创建满足我需要的完美字典(包含带有值和列表的字典的字典)。然而,我似乎一遍又一遍地分配相同的引用。 brands = ['val1', 'val2', 'val3'] infoBrands =
这个问题已经有答案了: dict.fromkeys all point to same list [duplicate] How do I create a unique value for each
我写了下面的函数。它在不应该的时候返回一个空字典。该代码在没有功能的命令行上运行。但是我看不出这个函数有什么问题,所以我不得不求助于你们的集体智慧。 def enter_users_into_dict
我们可以从键列表中初始化一个新的字典实例: >>> dict.fromkeys(['spam', 'spam', 'potato']) {'potato': None, 'spam': None} q
我有以下字典: ref_range = range(0,100) aas = list("ACDEFGHIKLMNPQRSTVWXY*") new_dict = {} new_dict = new_d
为什么 dict.fromkeys 的函数描述符功能不同于其他正常功能。 首先你无法访问__get__像这样:dict.fromkeys.__get__你必须从 __dict__ 得到它. ( dic
这是一个例子, my_keys=['hi','hello'] d=dict.fromkeys(my_keys,[]) print d d['hello'].append([1,]) print d['
我有一个继承自collections.Counter的Python类: class Analyzer(collections.Counter): pass 当我在这段代码上使用 pylint 时
代码如下: from collections import defaultdict result = defaultdict.fromkeys(['a','b','c'], list) result[
def parse_urls(weeks_urls): for wkey in weeks_urls.keys(): results=urllib2.urlopen(weeks
首先,我是 Python 的新手,所以如果我忽略了什么,我深表歉意,但我想使用 dict.fromkeys(或类似的东西)来创建列表字典,其中的键在另一个列表中提供。我正在执行一些计时测试,我希望键成
这个问题在这里已经有了答案: How can I initialize a dictionary of distinct empty lists in Python? (7 个回答) 关闭2年前。 我
这个问题在这里已经有了答案: How can I initialize a dictionary of distinct empty lists in Python? (7 个回答) 关闭 10 个月
dict 方法 {}.fromkeys() 接受一个可迭代的字符串,它将被转换为字典键。默认值将默认为 None。例如: d = {}.fromkeys(['loss', 'val_loss']) {
在 Python 中,您可以使用字典作为 dict.fromkeys() 的第一个参数,例如: In [1]: d = {'a': 1, 'b': 2} In [2]: dict.fromkeys(d
基于Python2.7字典的键必须是不可变的和可哈希的吗?在列表实现中,我发现 __hash__=None,这意味着它不可哈希。 我们可以使用 fromkeys 来创建这样的字典: d={}.from
这个问题在这里已经有了答案: How do I initialize a dictionary of empty lists in Python? (7 个答案) 关闭去年。 我怎样才能绕过这个限制
我是一名优秀的程序员,十分优秀!