Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82537

Re: Classes - converting external function to class's method.

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.python
Subject Re: Classes - converting external function to class's method.
Date 2014-12-15 01:32 +0100
Organization solani.org
Message-ID <3517223.7xnpL0NDtR@PointedEars.de> (permalink)
References <mailman.16949.1418574125.18130.python-list@python.org> <2082416.uXDKvNnAXg@PointedEars.de> <mailman.16964.1418602282.18130.python-list@python.org>

Show all headers | View raw


Terry Reedy wrote:

> On 12/14/2014 6:15 PM, Thomas 'PointedEars' Lahn wrote:
>> Ivan Evstegneev wrote:
>>> I have stuck a bit with this example(took this one from the book).
>>>
>>> Here are a description steps of what I've done till now:
>>>
>>> Step 1 - creating an empty namespace:
>>>
>>>>>> class rec: pass
>>
>> IMHO that is not actually creating a namespace; it is just
>> declaring/defining an empty class.
> 
> I pythonland, a namespace is a many to one mapping between names and
> objects.  They are usually but not necessarily implemented with dicts.
> […]
> 
>> BTW, the recommended Python 3.x way is
>>
>> class Rec (object):
>>      pass
> 
> I hope you meant Python *2*.x,

I did not.

> where '(object)' *is* needed to make a newstyle class.  In 3.x, '(object)' 
> is optional and normally omitted except in code meant to run unchanged in 
> 2 and 3.

Your statements are corroborated by the Language Reference:

<https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces>

<https://docs.python.org/2.7/reference/datamodel.html#new-style-and-classic-classes>

Thanks.

-- 
PointedEars

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Classes - converting external function to class's method. "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-12-14 18:20 +0200
  Re: Classes - converting external function to class's method. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-15 04:28 +1100
    RE: Classes - converting external function to class's method. "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-12-14 21:49 +0200
  Re: Classes - converting external function to class's method. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-15 00:15 +0100
    Re: Classes - converting external function to class's method. Terry Reedy <tjreedy@udel.edu> - 2014-12-14 19:11 -0500
      Re: Classes - converting external function to class's method. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-15 01:32 +0100
    Re: Classes - converting external function to class's method. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-15 13:01 +1100
      RE: Classes - converting external function to class's method. "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-12-15 21:13 +0200

csiph-web