继承自对象 [英] Inheriting from object

查看:65
本文介绍了继承自对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


要创建经典(旧式)课程,我写道:


class foo:

通过


为了做同样的新风格,我写道:


class foo(object):

通过


*应该*我实际上写道:


class foo(对象):

def __init __(self,* args,** kwargs):

object .__ init __(self)





此外,有没有人可以解释从

对象继承的任何实际好处,当没有明确使用新样式类的任何功能时?


谢谢: - )


Fuzzyman
http ://www.voidspace.org.uk/python

Hello,

To create a classic (old style) class, I write :

class foo:
pass

To do the equivalent as a new style class, I write :

class foo(object):
pass

*Should* I in fact write :

class foo(object):
def __init__(self, *args, **kwargs):
object.__init__(self)

?

Also, can anyone explain any tangible benefit of inheriting from
object, when not explicitly using any features of new style classes ?

Thanks :-)

Fuzzyman
http://www.voidspace.org.uk/python

推荐答案

Fuzzyman写道:
Fuzzyman wrote:
你好,

要创建一个经典(旧式)课程,我写道:

class foo:
传递

为了做一个新的风格等级,我写道:

类foo(对象):
传递

*应该*我实际上写道: def __init __(self,* args,** kwargs):
对象.__ init __(自我)




我不相信。

此外,任何人都可以解释从
对象继承的任何实际好处,当没有明确使用任何新风格类的功能?
Hello,

To create a classic (old style) class, I write :

class foo:
pass

To do the equivalent as a new style class, I write :

class foo(object):
pass

*Should* I in fact write :

class foo(object):
def __init__(self, *args, **kwargs):
object.__init__(self)

?
I don''t believe so.
Also, can anyone explain any tangible benefit of inheriting from
object, when not explicitly using any features of new style classes ?




这个类可能没有,但是你(或其他人)可能稍后决定

子类化它并且想要使用这些功能。即使你最初没有计划使用这些功能,这也是获得

的好习惯。


-

Robert Kern
rk***@ucsd.edu


在地狱的地方,草地长得很高

梦想的坟墓是否已经死亡。

- 理查德·哈特


Fuzzymanaécrit:
Fuzzyman a écrit :
你好,

要创建一个经典(旧式)类,我写道:
foo:
传递

为了做一个新的风格类,我写道:

类foo(对象):
传递

*应该*我实际上写道:

类foo(对象):
def __init __(self,* args,** kwargs):
对象.__ init __(自我)




Nope。

此外,当没有明确使用新样式类的任何功能时,是否可以解释从
对象继承的任何实际好处?
Hello,

To create a classic (old style) class, I write :

class foo:
pass

To do the equivalent as a new style class, I write :

class foo(object):
pass

*Should* I in fact write :

class foo(object):
def __init__(self, *args, **kwargs):
object.__init__(self)

?
Nope.
Also, can anyone explain any tangible benefit of inheriting from
object, when not explicitly using any features of new style classes ?




旧式类已弃用。出于兼容性原因,它们仍然使用语言(因为

需要多长时间?),但它们不会永远存在。

这应该是一个足够的理由避免它们,因为

唯一需要做的就是从对象继承...



old-style classes are deprecated. They are still in the language (for
how much time ?) for compatibility reasons, but they won''t last forever.
That should be a good enough reason to avoid them, given that the
only thing you have to do is to inherit from object...


Fuzzyman写道:
Fuzzyman wrote:
此外,任何人都可以解释从
对象继承的任何实际好处,当没有明确使用新样式类的任何功能时?
Also, can anyone explain any tangible benefit of inheriting from
object, when not explicitly using any features of new style classes ?




一个原因是属性不能正常工作。

-

Benji York



One reason is that properties won''t work correctly.
--
Benji York


这篇关于继承自对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆