Why should I use CamelCase for namedtuple?

和自甴很熟 提交于 2021-01-28 18:28:17

问题


Assuming this code snippet (ipython)

In [1]: from collections import namedtuple
In [2]: type(namedtuple)
Out[2]: function

you can see that factory function namedtuple is a function, of course. I can't see any hint in PEP-8 to use the naming convention for classes in that case. I can only see that the documentation treating it like a class as a naming convention.

Why should one use the naming convention for classes in that case?


回答1:


You're referring to the use of the name Point for the type returned by namedtuple. namedtuple is a function alright, but it returns a class (a thing that has the type type). And by PEP-8, class names should look LikeThis.

In [1]: from collections import namedtuple
In [2]: Point = namedtuple('Point', ['x', 'y'])
In [3]: type(Point)
Out[3]: type


来源:https://stackoverflow.com/questions/33259220/why-should-i-use-camelcase-for-namedtuple

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!