Python for Dummies exaple

Chris Angelico rosuav at gmail.com
Wed Oct 14 09:02:43 EDT 2015


On Wed, Oct 14, 2015 at 11:47 PM, Peter Otten <__peter__ at web.de> wrote:
> Chris Angelico wrote:
>
>> On Wed, Oct 14, 2015 at 8:55 PM, NewsLeecher User <newsleecher at spam.com>
>> wrote:
>>> #class example
>>> class SayMyName:
>>>     def __init__(self, myname):
>>>         self.myname = myname
>>>     def say(self):
>>>         print "Hello, my name is", self.myname
>>
>> Side point: This is a poor example for _any_ Python. In Py2, that
>> makes an old-style class, which will work fine until you try to use a
>> feature that it can't handle, and then you'll wonder what on earth is
>> wrong. And in Py3, the print calls need their parens. But it's a
>> pointless example of a class, which leaves you wondering why a better
>> example couldn't be found...
>>
>> Definitely look for a better book, preferably one aimed at Python 3.4 or
>> 3.5.
>
> If I were to write a book about Python 2 I would defer the "always inherit
> from object" mantra until the features that require newstyle classes are
> introduced. In any way, judging a book from one example you disagree with is
> premature. Personally I expect to find many minor nits in the most excellent
> book.

Agreed, which is why I prefixed that part with "Side point". The
old-style vs new-style class concern is a very minor one. The reason I
recommend looking for a better book is mainly because people should be
learning Py3 with a Py3 book.

> OP, the differences between Python 2 and Python 3 are big enough to make the
> attempt to learn one with a book using the other a rather displeasant
> experience. Either switch to a book that is geared at Python 3 (recommended,
> particularly if you speak a language using non-ascii letters) or install
> Python 2 and run the examples from your current book with the older 2.7
> interpreter.

Yeah. Those are the two options, and I definitely recommend the
former. The advantages of Py3 over Py2 increase with every new
version.

ChrisA



More information about the Python-list mailing list