当前位置: 动力学知识库 > 问答 > 编程问答 >

Python Static class variables

问题描述:

If all I need is to use it as constant enum, is it still better to use "object" ?

class COLOR:

RED = 1

BLUE = 2

GREEN = 3

vs

class COLOR(object):

RED = 1

BLUE = 2

GREEN = 3

网友答案:

In Python3, there is no difference (all classes are "new style")

In Python2 newstyle classes are usually considered to be faster. I'm not sure if there's a difference for such a trivial class though

网友答案:

Yes, it is better to use object as the base. There are a few subtle differences, and when you come back in six months, add some new functionality, and don't then subclass from object, you'll likely waste valuable time trying to figure out why something isn't working.

分享给朋友:
您可能感兴趣的文章:
随机阅读: