[PATCH] A compromise on case

Mikael Olofsson mikael at isy.liu.se
Fri May 26 03:17:50 EDT 2000


On 26-May-00 Nick Mathewson wrote:
 >    >>> class NumHolder:
 >    ...     def __init__(self, num):
 >    ...         self.x = num
 >    ...     def get(self):
 >    ...         return x
 >    ...
 >    >>> NumHolder(5).get()
 >    Traceback (most recent call last):
 >       File "<stdin>", line 1, in ?
 >       File "<stdin>", line 5, in get
 >    NameError: No such name as 'x'. Perhaps you meant 'self.x'?
 >  
 >  Forgetting 'self' is one of the most common beginner errors on
 >  comp.lang.python.  The extra code required to detect it: 4 lines!

Beautiful!

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    26-May-00
Time:    09:17:29

This message was sent by XF-Mail.
-----------------------------------------------------------------------



More information about the Python-list mailing list