什么是新式课程? [英] What are new-style classes?

查看:87
本文介绍了什么是新式课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近听说过''新式课程''。如果这个

听起来像是一个新手问题,我很抱歉,但它们是什么?我检查了Python

手册,但没有找到任何结论。请有人请

赐教我?谢谢!

I recently heard about ''new-style classes''. I am very sorry if this
sounds like a newbie question, but what are they? I checked the Python
Manual but did not find anything conclusive. Could someone please
enlighten me? Thanks!

推荐答案

Vaibhav写道:
Vaibhav wrote:
我最近听说''新式课'' 。如果这听起来像是一个新手问题,我很抱歉,但他们是什么?我检查了Python
手册,但没有找到任何结论。有人可以请赐教吗?谢谢!
I recently heard about ''new-style classes''. I am very sorry if this
sounds like a newbie question, but what are they? I checked the Python
Manual but did not find anything conclusive. Could someone please
enlighten me? Thanks!




http://docs.python.org

http://www.python.org/doc/newstyle.html

-

Robert Kern
rk***@ucsd.edu


在字段中草地长高的地狱

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

- Richard Harter



There''s a link on the left sidebar of http://docs.python.org

http://www.python.org/doc/newstyle.html

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter


Vaibhav写道:
Vaibhav wrote:
我最近听说''新式课''。如果这听起来像是一个新手问题,我很抱歉,但他们是什么?我检查了Python
手册,但没有找到任何结论。有人可以请赐教吗?谢谢!
I recently heard about ''new-style classes''. I am very sorry if this
sounds like a newbie question, but what are they? I checked the Python
Manual but did not find anything conclusive. Could someone please
enlighten me? Thanks!



较旧的Pythons在程序员声明的对象

类(子类可以继承)和内置对象之间存在二分法

类(它只是作为内置存在,但不能用作子类基础的
)。


最近对象层次结构经过重新设计,现在所有内容都是从对象继承的,所以(如果你知道自己在做什么),你可以实现内置类型的子类,比如
dict,float和str。


Robert Kern给了你一个详细说明情况的链接。


问候

史蒂夫

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC http://www.holdenweb.com/


Older Pythons have a dichotomy between programmer-declared object
classes (from which subclasses can inherit) and the built-in object
classes (which just existed as built-in, but which could not be used as
the base of subclasses).

More recently the object hierarchy was redesigned, and now everything
inherits from object, so (if you know what you are doing) you can
implement subclasses of the built-in types such as dict, float and str.

Robert Kern has given you a link that explains the situation in detail.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/


2005年8月28日星期日上午04:47,Vaibhav写道:
On Sunday 28 August 2005 04:47 am, Vaibhav wrote:
我最近听说''新式课''。如果这听起来像是一个新手问题,我很抱歉,但他们是什么?我检查了Python
手册,但没有找到任何结论。有人可以请赐教吗?谢谢!
I recently heard about ''new-style classes''. I am very sorry if this
sounds like a newbie question, but what are they? I checked the Python
Manual but did not find anything conclusive. Could someone please
enlighten me? Thanks!




新风格类正在成为Python的标准,并且必须始终将
声明为新样式类的子类,包括内置的

类。最简单的是对象,所以最简单的newstyle类是:


class no_class(object):

pass


而不是最简单的旧式根本没有继承的对象:


class really_no_class:

pass


我会认为后者现在已经弃用了,因为它基本上不会给你带来任何使用它的东西。坚持旧式

类的唯一理由似乎是避免破坏依赖于

细节的旧代码,例如多重继承的顺序,这已经改变了。


因此,如果您只是学习,只需使用新的样式类,并且

使用适用于它们的文档。我认为新风格的类型是一种改进的设计,这是非常有价值的。


-

特里Hancock(hancock at anansispaceworks.com)

Anansi Spaceworks http:// www。 anansispaceworks.com



"New style" classes are becoming the standard in Python, and must
always be declared as a subclass of a new style class, including built-in
classes. The simplest is "object", so the simplest newstyle class is:

class no_class(object):
pass

as opposed to the simplest "old style" object which didn''t inherit at all:

class really_no_class:
pass

I would regard the latter as deprecated now, since it basically doesn''t
buy you anything to use it. The only reason to hang on to old style
classes would seem to be to avoid breaking older code that relied on
details such as the order of multiple inheritence, which have changed.

So if you''re just learning, just use new style classes exclusively, and
use the documentation that applies to them. I think it''s fairly non-
controversial that new style classes are an improved design.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com


这篇关于什么是新式课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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