Sunday, February 24, 2013

Basics of class implementation in Python

By reading ten pages of Chapter five today, I learnt instantiation and attributes. Here is what I programmed during reading the book:


class NewClass:
    pass;
dir(NewClass);
# Result: ['__doc__', '__module__'] #
class NewClass(object):
    pass;
     
dir(NewClass);
# Result: ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] #
instance1 = NewClass();
instance2 = NewClass();
instance3 = NewClass();
class NewClass():
    data_attribute = None;
    def function_attribute(*args):pass;
print(dir(NewClass));
['__doc__', '__module__', 'data_attribute', 'function_attribute']

No comments:

Post a Comment