- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
为什么要混合使用小写字母和大驼峰字母?
namedtuple
deque
Counter
OrderedDict
defaultdict
为什么使用 collections
而不是 Collections
?
我有时会这样做,例如:
from collections import default_dict
错误。我可以使用什么经验法则来避免将来出现此类错误?
最佳答案
集合模块遵循 PEP 8 Style Guide :
Modules should have short, all-lowercase names.
这就是为什么它是collections
Almost without exception, class names use the CapWords convention.
这就是为什么它是Counter
和OrderedDict
,因为它们都是类:
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
namedtuple
是一个函数,所以它不遵循上面提到的风格指南。 deque
和 defaultdict
是类型,所以它们也不是:
>>> collections.deque
<type 'collections.deque'>
>>> collections.namedtuple
<function namedtuple at 0x10070f140>
>>> collections.defaultdict
<type 'collections.defaultdict'>
注意:在 Python 3.5 中,defaultdict 和 deque 现在也是类:
>>> import collections
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
>>> collections.defaultdict
<class 'collections.defaultdict'>
>>> collections.deque
<class 'collections.deque'>
我假设他们将 defaultdict
和 deque
保留为小写以便向后兼容。我无法想象他们会为了风格指南而做出如此剧烈的名称更改。
关于python - 集合中的命名约定 : why are some lowercase and others CapWords?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18953681/
我的问题:我必须使用 ngSanitize 模块,但是当我运行该项目时,出现以下错误: Failed to instantiate module ngSanitize due to:lowercase
我在使用Electron的React w/react-photonkit绊了一下,这增加了一些不利因素。我正在尝试基于主侧菜单在光子header中创建动态水平菜单,以便在主要更改时触发水平选项进行更新
我有一个任务,描述如下: - Reads printable characters (20h-7Fh) from the keyboard without echoing - Uppercase le
在 Rails 3.2 应用程序中,我有一个 Tag模型,并希望找到 name:string 中值所在的所有记录字段全部小写。 因此 activerecord 查询(在 Postgres 上)将返回
我想知道如何将特定索引打印为大写和小写? 我不知道特定索引会发生变化吗? 对于单个索引,这是代码... public class UpperAndLowerCase { public stat
我尝试创建一个搜索器并过滤每个注册用户的结果,但我得到的只是“'User' 类型的值没有成员'lowercased'”作为错误... 错误出现在下一行 let searchedUser = users
我在这里有点困惑,出于某种原因我不能以相同的方式调用 capitalized 和 lowercased,即使两者都应该是实例属性: var aString = "a lowercased string
我目前使用以下代码从数据框中选择行: list = ['3d block','3D Block','3D block','3d Block','cafe','Cafe'] data[data['des
如标题所述:将字符串从任意大小写转换为小写并保持部分不变的最佳方法是什么?例如一个字符串,如:FormatDate(%M)==2 或 stArTDate(%Y/%m)==11/3 我想将其转换为 fo
我想将所有表名都保留为小写。示例 人 我使用 Liquibase设置我的数据库,它看起来像 Add Person Table
我想我在导入 pylab 时遇到了问题。导入 numpy 时会出现类似的错误。这是我的代码 from math import radians, sin, cos from pylab import p
为什么要混合使用小写字母和大驼峰字母? namedtuple deque Counter OrderedDict defaultdict 为什么使用 collections 而不是 Collect
我有一个搜索字符串数组的函数。它工作得很好,除了它区分大小写。我需要它不区分大小写。 最简单的方法是让函数将数组转换为小写,这样当函数在数组中执行搜索时,无论大小写如何,它都能找到它。 我尝试在我的函
如果后续字符不是小写,我如何保留所有大写字符? 考虑这个例子: import re test1 = 'ThisIsATestTHISISATestTHISISATEST' re.findall(r'[
我有以下 text_field: 哪些输出: 手头的问题是:我的属性是 data-date-clearBtn,但 Rails 呈现 data-date-clearbtn(小写 b)。我怎样才能避免
我开始使用 Apache Lucene 8.0。我想知道如何使用 Lucene 将我的 String text 变量转换为小写。我不太确定如何做到这一点,因为我找不到任何例子。我想要的是这样的: pu
我正在尝试用 Atom 编辑器中的大写/小写等效项替换字符串中的某些字符。 假设我有字符串: some:test:sequence 并想要结果: Some:Test:Sequence 我知道诸如 \u
我有点被这个问题困住了。当我运行程序时,由于某种原因,循环经过 z 的所有字母都不会打印。问题来自这个链接:http://docs.cs50.net/2016/x/ap/problems/caesar
我已经搜索过 SO 和 Google,我发现的大多数示例似乎都没有按预期工作(或者没有结合所有这些元素)。我正在尝试创建一个 Regex 表达式,如果字符串包含 至少 字符串中的以下 anywhere
很抱歉这里有很多代码......我尽量让它尽可能短: 我写了(主要是从这里偷来的)一个 HtmlHelper 扩展来写出一个基于枚举的 RadioButton(分组)。我还设置了我的路线图,因此它使用
我是一名优秀的程序员,十分优秀!