我应该在书中放置旧式还是新式? [英] should I put old or new style classes in my book?

查看:66
本文介绍了我应该在书中放置旧式还是新式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在修改如何像计算机一样思考

科学家,

这将被称为Think Python。它将由

剑桥

大学出版社出版,但GNU下仍有免费版本

FDL。


您可以在thinkpython.com上看到最新版本;我现在正在修改,

所以

我欢迎所有评论,建议,更正等。


无论如何,我发帖询问新风格的现状

课程。

我打算在书中只提出一种风格,因为

的差异
他们之间的
对于我在书中所做的任何事情都不重要。


本书的当前版本介绍旧式课程。我是

考虑

切换到新款式,假设这应该是

默认

选择对于新节目。缺点是很多在线

文件

仍然使用旧式的课程。


感谢你的任何指导你可以提供。


干杯,

Allen

解决方案

5月29日上午10:07,allendow ... @ gmail.com写道:


大家好,


我正在修改一个如何像计算机一样思考的版本

科学家,

这将被称为Think Python。它将由

剑桥

大学出版社出版,但GNU下仍有免费版本

FDL。


您可以在thinkpython.com上看到最新版本;我现在正在修改,

所以

我欢迎所有评论,建议,更正等。


无论如何,我发帖询问新风格的现状

课程。

我打算在书中只提出一种风格,因为

的差异
他们之间的
对于我在书中所做的任何事情都不重要。


本书的当前版本介绍旧式课程。我是

考虑

切换到新款式,假设这应该是

默认

选择对于新节目。缺点是很多在线

文件

仍然使用旧式的课程。


感谢你的任何指导你可以提供。


干杯,

Allen



我有Python 3.0 alpha 2在这个版本中,看起来你可以用旧样式或新样式来定义类。 (我在下面的例子中略过了

的顶线):


Python 3.0a2(r30a2:59405M,2007年12月7日,15:23: 28

输入help,copyright,credit或license

< blockquote class =post_quotes>
>> class one(object):传递



....


>> class two:pass



....


>>两个



< class''__ main __。two''>


>>一个



< class''__ main __。one''>


>> type(one)



< type''type''>


>> type(two)



< type''type''>


>>>



也就是说,旧式的类不能正确使用staticmethod或classmethod

属性。新式类更好地支持多个继承,而旧式类不能使用元类。元类,

甚至多重继承都可能超出了你的书的范围,

虽然。


我会推荐我自己的新式课程,因为如果你的读者转向更高级的技术,它可以避免一些令人讨厌的微妙的问题。但是,你是b $ b正确的,Python库中的一些类使用旧样式的




所以,你可能要承认有两种方法可以做

类,很多旧代码都使用旧方法。新的方式增加了一些强大的新技术,可能超出了你的b
书的范围。在Python 3.0中,它无关紧要,因为无论如何一切都是新式的

类。


--Jason


Jason< te *********** @ gmail.comwrites:


5月29日,10日:07 am,allendow ... @ gmail.com写道:


>大家好,

我正在修改版本如何像计算机一样思考
科学家,
这将被称为Think Python。它将由剑桥大学出版社出版,但GNU
FDL下仍会有免费版本。

您可以在thinkpython上看到最新版本.COM;我正在修改,
所以
我欢迎所有评论,建议,更正等等。

无论如何,我发帖询问新风格的现状课程。
我打算在书中只提出一种风格,因为它们之间的差异对于我在书中所做的任何事情都不重要。

本书的当前版本介绍了旧式课程。我正在考虑转换到新的风格类,假设这应该是新程序的默认选择。缺点是许多在线
文档仍然使用旧式的类。

感谢您提供的任何指导。

干杯,
Allen



我有Python 3.0 alpha 2.在这个版本中,看起来你可以

定义类无论是旧式还是新式。 (我在下面的例子中略过了

的顶线):


Python 3.0a2(r30a2:59405M,2007年12月7日,15:23: 28

输入help,copyright,credit或license


>>>第一类(对象):传递



...


>>>第二类:传递



...


>>>两个



< class ''__main __。two''>


>>> one



< class''__ main __。one''>


>>>类型(一)



< type''type''>


>>> type(two)



< type''type''>


>>>>



请注意,通过设置

全局变量__metaclass__,您可以在Python 2.2+中获得相同的行为输入:


万寿菊:~arno


python

Python 2.5.1(r251:54863,Jan 17 2008年,19:35:17)

[GCC 4.0.1(Apple Inc. build 5465)]在darwin上

输入help,copyright, "币"或许可证或欲获得更多信息。


>> __ metaclass__ = type
class Foo:pass



....


>> type(Foo)



< type''type''>


>>>



-

Arnaud


Hi All,

I am working on a revised edition of How To Think Like a Computer
Scientist,
which is going to be called Think Python. It will be published by
Cambridge
University Press, but there will still be a free version under the GNU
FDL.

You can see the latest version at thinkpython.com; I am revising now,
so
I welcome all comments, suggestions, corrections, etc.

Anyway, I am posting to ask about the current status of new style
classes.
I am planning to present only one style in the book, because the
differences
between them don''t matter for anything I am doing in the book.

The current edition of the book presents old style classes. I am
considering
switching to new style classes on the assumption that this should be
the default
choice for new programs. The drawback is that a lot of the online
documentation
still uses old style classes.

Thanks for any guidance you can provide.

Cheers,
Allen

解决方案

On May 29, 10:07 am, allendow...@gmail.com wrote:

Hi All,

I am working on a revised edition of How To Think Like a Computer
Scientist,
which is going to be called Think Python. It will be published by
Cambridge
University Press, but there will still be a free version under the GNU
FDL.

You can see the latest version at thinkpython.com; I am revising now,
so
I welcome all comments, suggestions, corrections, etc.

Anyway, I am posting to ask about the current status of new style
classes.
I am planning to present only one style in the book, because the
differences
between them don''t matter for anything I am doing in the book.

The current edition of the book presents old style classes. I am
considering
switching to new style classes on the assumption that this should be
the default
choice for new programs. The drawback is that a lot of the online
documentation
still uses old style classes.

Thanks for any guidance you can provide.

Cheers,
Allen

I''ve got Python 3.0 alpha 2. In this version, it looks like you can
define classes in either the old style or new style. (I snipped the
top line a bit in the following example):

Python 3.0a2 (r30a2:59405M, Dec 7 2007, 15:23:28
Type "help", "copyright", "credits" or "license"

>>class one(object): pass

....

>>class two: pass

....

>>two

<class ''__main__.two''>

>>one

<class ''__main__.one''>

>>type(one)

<type ''type''>

>>type(two)

<type ''type''>

>>>

That said, old-style classes can''t use the staticmethod or classmethod
properties correctly. New-style classes better support multiple
inheritance and old-style classes can''t use metaclasses. Metaclasses,
and even multiple inheritance may be beyond the scope of your book,
though.

I''d recommend new-style classes myself, as it avoids some nasty subtle
problems if your readers move to more advanced techniques. You are
correct, though, that some of the classes in the Python library use
the old style.

So, you might want to acknowledge that there are two ways of doing
classes, that a lot of old code uses the old way. The new way adds
some powerful new techniques that may be beyond the scope of your
book. In Python 3.0, it won''t matter, as everything is a new-style
class anyway.

--Jason


Jason <te***********@gmail.comwrites:

On May 29, 10:07 am, allendow...@gmail.com wrote:

>Hi All,

I am working on a revised edition of How To Think Like a Computer
Scientist,
which is going to be called Think Python. It will be published by
Cambridge
University Press, but there will still be a free version under the GNU
FDL.

You can see the latest version at thinkpython.com; I am revising now,
so
I welcome all comments, suggestions, corrections, etc.

Anyway, I am posting to ask about the current status of new style
classes.
I am planning to present only one style in the book, because the
differences
between them don''t matter for anything I am doing in the book.

The current edition of the book presents old style classes. I am
considering
switching to new style classes on the assumption that this should be
the default
choice for new programs. The drawback is that a lot of the online
documentation
still uses old style classes.

Thanks for any guidance you can provide.

Cheers,
Allen


I''ve got Python 3.0 alpha 2. In this version, it looks like you can
define classes in either the old style or new style. (I snipped the
top line a bit in the following example):

Python 3.0a2 (r30a2:59405M, Dec 7 2007, 15:23:28
Type "help", "copyright", "credits" or "license"

>>>class one(object): pass

...

>>>class two: pass

...

>>>two

<class ''__main__.two''>

>>>one

<class ''__main__.one''>

>>>type(one)

<type ''type''>

>>>type(two)

<type ''type''>

>>>>

Note that you can get the same behaviour in Python 2.2+ by setting the
global variable __metaclass__ to type:

marigold:~ arno


python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>__metaclass__ = type
class Foo: pass

....

>>type(Foo)

<type ''type''>

>>>

--
Arnaud


这篇关于我应该在书中放置旧式还是新式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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