- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
这只是出于历史目的的好奇:
我想知道是否有人知道为什么使用非常广泛(和核心模块)logging不遵循 Python 的 PEP-8 naming convention .
例如,在
>>> import logging
>>> log = logging.getLogger("hello")
我希望它是 get_logger
,但它不是。
说到function names ,PEP8 标准说:
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
是这样吗?如果是这样,它必须使用什么其他 logging
东西来保持向后兼容性?还是只是 logging
的开发者喜欢使用驼峰命名法?
当然,该模块是有据可查的,根本不是什么大问题。我只是好奇。
最佳答案
logging
模块由 separate company 开发2001 年,主要基于 Log4j。因此,它遵循原作者选择的命名约定,反射(reflect)了 Log4j 的选择;后者有 getLogger()
method too .
直到一年后 PEP 282建议将其添加到标准库中,到那时命名约定已经确定。
这是一个 known issue with the package ,但它不是唯一违反 PEP 的包。来自链接的 Wiki:
PEP8 says - consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.
- So True, but can't not be changed, because of backward compatibility. logging2 maybe. -- techtonik
- It's a low priority right now, unless there's an initiative to ensure the rest of the stdlib is made to conform to PEP8. -- VinaySajip
最后但同样重要的是,styleguide itself关于应用样式指南有这样的说法:
A Foolish Consistency is the Hobgoblin of Little Minds
A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.
But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!
In particular: do not break backwards compatibility just to comply with this PEP!
'Fixing' logging
会破坏向后兼容性,这是不值得的。
关于python - 为什么 Python 的日志记录模块不遵循 PEP8 约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22993667/
我有关于 PEP 代理文件的问题。我的 keystone 服务运行在 192.168.4.33:5000 上。我的 Horizon 服务正在 192.168.4.33:443 上运行。 我的 We
PEP 状态的结构和含义是什么? 这几天尝试写一个python2.7的解释器。 但是,我不知道为什么比较运算符 <> 出现在 python 2.7 中。 (它不在 python 3.0 中)找出它在
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 1 年前。 Improve
我的问题与 XACML 上下文处理程序的角色和目的有关。如果我正确理解 OASIS XACML3.0 规范,PEP 会拦截来自客户端应用程序的对某些资源或访问的请求,然后使用上下文处理程序创建适合 P
我正计划为我正在研究的项目设置一些传感器。我计划在每个装有传感器的设备上使用一个简单的xmpp客户端,并通过PEP / PubSub发布读数。 我想运行一个程序,该程序会在收到来自传感器客户端的推送通
我一直在研究 PEP-Proxy-Steelskin,以便我可以为我的 Orion Context 提供一些安全层,但是,有一些问题阻碍了我的进展。 我想使用 IDM 和 Keystone 全局实例。
如果我使用 PEP-526 作为类级变量,我必须将它们记录在类的文档字符串中,在这种情况下,我需要选择我最喜欢的方式来执行此操作。 Python 3.6.4 pylint==1.8.4 class J
我正在寻找任何 PEP 3124实现或开发过程。我对邮件列表不太熟悉,但去年Python邮件列表中似乎没有出现序列“3124”。有关于此 PEP 的一些信息吗? 最佳答案 Most of the fu
我很好奇 PEP 232 (函数的属性)也适用于类方法。最后,我认为它没有或者我做错了什么? Python 2.7.6 (default, Feb 26 2014, 12:07:17) [GCC 4.
我最近一直在尝试学习 WSGI 以及网络如何在 Python 方面工作。所以我一直在阅读 Werkzeug 和 PEP333 来学习。 但是我遇到了一个小问题,我认为我理解但可能不理解,所以我希望您能
我必须在 Python 中声明一些 dict。我写了这样一段代码: class MegaClass(object): _activation_grad_classes = \ {
PEP-484 为类型注释提供了语义。这些非常适合 a) 文档和 b) IDE 帮助。它们不太适合代码优化。 例如,不幸的是,Cython 无法使用 PEP 484 注释 https://groups
假设我有一个函数会根据字符串输入参数返回一个类,如下所示: def foo(bar): if bar == 'baz': return Baz() else:
我正在开发一个大型 Python 程序,它根据命令行选项使用大量模块,特别是 numpy。我们最近发现需要在一个小的嵌入式模块上运行它,它排除了 numpy 的使用。从我们的角度来看,这很容易(只是不
我正在使用 PyCharm 和选项卡。如果有一个需要传递多个参数的函数,我可以这样做,效果很好: return render( request, '/post/list.html',
接受PEP 448 在 Python 3.5 中引入了其他解包通用化。 例如: >>> l1 = [1, 2, 3] >>> l2 = [4, 5, 6] # unpack both iterable
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 8 年前。 Improve
我对 PEP 8 中的样式有疑问(或将每行中的字符数减少到更小)。 假设我有一本包含许多不同属性的book,我想将它们连接成一些字符串。 books = [book_1, book_2, book_3
在PEP 8 Style Guide for Python Code , Naming Conventions 下列出的第一条规则是首要原则。 Overriding Principle Names t
我在 python 中有一个函数,它返回一个类而不是一个实例。如何指示返回值是特定类型的子类? 在下面的例子中,我将返回值设置为类型,但我想进一步说明该类型具有BaseClass的所有属性: from
我是一名优秀的程序员,十分优秀!