Re: should I put old or new style classes in my book?
Alan Isaac [EMAIL PROTECTED] writes: This thread raises two questions for me. 1. I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Is that correct, and if so, where is it stated explicitly? (I know about the all classes are new style classes statement.) I don't know where it is stated, but how could they *not* be equivalent? 2. I take it from this thread that in Python 2.2+ if I put the following at the top of a module :: __metaclass__ = type then all the classes defined in that module will be newstyle classes. Is that correct? Somehow I did not grok that from URL:http://docs.python.org/ref/metaclasses.html but it seems right. From the URL you quote: The appropriate metaclass is determined by the following precedence rules: * If dict['__metaclass__'] exists, it is used. * Otherwise, if there is at least one base class, its metaclass is used (this looks for a __class__ attribute first and if not found, uses its type). * Otherwise, if a global variable named __metaclass__ exists, it is used. * Otherwise, the old-style, classic metaclass (types.ClassType) is used. Look at the third point. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
2008/5/29 Alan Isaac [EMAIL PROTECTED]: This thread raises two questions for me. 1. I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Is that correct, and if so, where is it stated explicitly? (I know about the all classes are new style classes statement.) All classes are new style classes, and the usual class MyClass(object) pass should be replaced by the first class MyClass: pass IIRC. I don't know ATM where I read it. Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On May 29, 12:07 pm, [EMAIL PROTECTED] wrote: 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. New style, all the way. The drawback you speak of for new-style classes I think is today more of a drawback for old-style. The problem is, when a newbie goes looking for examples, there is a lot of code out there that uses things like properties, type(instance), @staticmethods, and so on. Those won't work, and will confuse the hell out of newbies, if you teach them old-style. OTOH, the examples out there that are written for old-style usually still work for new-style classes. The only significant issue, as far as I'm concerned, is the list of bases. Which is why, even if you only cover new-style classes, it's important to at least mention that there used to exist old-style that don't list any bases (in Python 2.x). And then tell the user, We're not covering it, it's not something you need to worry about, and most of the time you can and should add (object) and the code will still work. And leave it at that--let the interested newbie seek out more information on their own. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On May 29, 6:07 pm, [EMAIL PROTECTED] wrote: 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. You should use new-style classes. It is the default in Python 2.6 and the only option in 3.0. These releases will be out before your book is on the market. -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
[EMAIL PROTECTED] a écrit : 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. Same remarks as anyone else that answered so far: definitively use new-style classes, and just add a note about the old-style syntax. -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On Thu, May 29, 2008 at 3:06 PM, Jason [EMAIL PROTECTED] wrote: 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): Wrong. Py3k Classes are always new-style. They subclass object implicitly when no superclass is given. 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' Both classes are new style. -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
Eduardo O. Padoan [EMAIL PROTECTED] writes: On Thu, May 29, 2008 at 3:06 PM, Jason [EMAIL PROTECTED] wrote: 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): Wrong. Py3k Classes are always new-style. They subclass object implicitly when no superclass is given. I think he was talking about syntax, not object types. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: 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. You've got a tough use-case. When is your book supposed to be done? To what extent to you want to make your book work with 3.x? Overall, I'm generally in favor of presenting both (I'm opposed to new-style-only), but in your case it sounds like just new-style would be better. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ Need a book? Use your library! -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
Alan Isaac [EMAIL PROTECTED] writes: I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Arnaud Delobelle wrote: I don't know where it is stated, but how could they *not* be equivalent? The most obvious way would be that the former became an illegal syntax. But in Python 3 alpha, it is accepted, so I assume that it will continue to be? Cheers, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
should I put old or new style classes in my book?
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
Hi, New style classes should be put as the default. This is what I did, based on the principle that new classes were introduces in Python 2.2 and that we are now at 2.5 and soon 2.6. Tutorials that use old style classes may be old and perhaps won't be updated ever. That's not a problem. Just tell people that there are two styles, but that new style classes are far more powerful and do what you think they should do. Matthieu 2008/5/29 [EMAIL PROTECTED]: 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 -- http://mail.python.org/mailman/listinfo/python-list -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On Thu, May 29, 2008 at 12:07 PM, [EMAIL PROTECTED] 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 http://mail.python.org/mailman/listinfo/python-list Definitely go with the new-style classes. Python 3 is coming out soon, which doesn't have classic classes. http://docs.python.org/dev/3.0/whatsnew/3.0.html#new-class-and-metaclass-stuff -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On May 29, 10:07 am, [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
Jason [EMAIL PROTECTED] writes: On May 29, 10:07 am, [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
This thread raises two questions for me. 1. I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Is that correct, and if so, where is it stated explicitly? (I know about the all classes are new style classes statement.) 2. I take it from this thread that in Python 2.2+ if I put the following at the top of a module :: __metaclass__ = type then all the classes defined in that module will be newstyle classes. Is that correct? Somehow I did not grok that from URL:http://docs.python.org/ref/metaclasses.html but it seems right. Thank you, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list