Classes - converting external function to class's method.
Terry Reedy
tjreedy at udel.edu
Sun Dec 14 19:11:04 EST 2014
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.
Some might restrict the term to a mapping with a .attribute interface
for getting and setting. Others consider any string-key dict to be a
namespace. The types module has a class SimpleNamespace. It has been
proposed to move it to builtins with the name 'namespace'.
> BTW, the recommended Python 3.x way is
>
> class Rec (object):
> pass
I hope you meant Python *2*.x, 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.
--
Terry Jan Reedy
More information about the Python-list
mailing list