为什么新的Python 2.5功能“C类()”回归旧式班? [英] Why new Python 2.5 feature "class C()" return old-style class ?

查看:70
本文介绍了为什么新的Python 2.5功能“C类()”回归旧式班?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Python开发人员。

For Python developers around.

来自Python 2.5 doc:
From Python 2.5 doc:



类定义中的基类列表现在可以为空。作为一个

的例子,现在这是合法的:

class C():

pass


很好但是为什么这个语法返回旧式类,与class C:,

相同而不是新样式class C(object): ?

旧式的课程有点弃用,几乎总是可以用新式的类取代
,所以这个语法可能是一个很好的快捷方式

创建它们。


我错了还是有什么我错过的?


The list of base classes in a class definition can now be empty. As an
example, this is now legal:
class C():
pass

nice but why this syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
Old-style class are somewhat deprecated and could be almost always be
replaced by new-style class, so this syntax could be a nice shortcut to
create them.

Am I wrong or is there something that I''ve missed ?

推荐答案

looping写道:
looping wrote:
对于Python开发人员来说。
For Python developers around.
来自Python 2.5 doc:
From Python 2.5 doc:


类定义中的基类列表现在可以为空。作为一个例子,现在这是合法的:
C类():


很好但为什么这种语法会返回旧式的类,与 C类:,
而非新风格C类(对象): ?
旧式的类有些不赞成,几乎总是被新式的类取代,所以这种语法可以成为创建它们的一个很好的捷径。
<我错了还是有什么我错过的?


The list of base classes in a class definition can now be empty. As an
example, this is now legal:
class C():
pass

nice but why this syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
Old-style class are somewhat deprecated and could be almost always be
replaced by new-style class, so this syntax could be a nice shortcut to
create them.

Am I wrong or is there something that I''ve missed ?




class C():


本来应该是


C级的代名词:


因此无法创建新式的课程。

Georg



class C():

is meant to be synonymous with

class C:

and therefore cannot create a new-style class.

Georg


Georg Brandl写道:
Georg Brandl wrote:
C类():

意味着C类的代名词:

因此无法创建新式的课程。
class C():

is meant to be synonymous with

class C:

and therefore cannot create a new-style class.




我认为& ;循环"理解这一点,但基本上是在问为什么有人为b / b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b换句话说,class():从来没有使用过
有效,为什么现在才使它有效?


-Peter


Peter Hansen写道:
Peter Hansen wrote:
Georg Brandl写道:
Georg Brandl wrote:
C类():

是本来是C级的同义词:

因此无法创建新式的课程。
class C():

is meant to be synonymous with

class C:

and therefore cannot create a new-style class.



我认为循环"理解这一点,但基本上是在问为什么有人为了改变而烦恼,因为这种改变涉及到有效弃用的语言的一部分。换句话说,class():从来没有过有效,所以为什么现在才使它有效?



I think "looping" understands that, but is basically asking why anyone
is bothering with a change that involves a part of the language that is
effectively deprecated. In other words, class(): never used to be
valid, so why make it valid now?




我不记得了,你我将不得不搜索python-dev档案。


Georg



I don''t recall that, you''ll have to search the python-dev archives.

Georg


这篇关于为什么新的Python 2.5功能“C类()”回归旧式班?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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