dot notation

You have made it through the end of the book. Do you understand the following?

AClass.attribute

in the same file

class AClass(object):

    attribute = None

or

class AClass(object):

    def __init__(self, attribute):
        self.attribute = attribute

AClass.method()

in the same file

class AClass(object):

    def method(self):
        return None

AClass.method(*args, **kwargs)

in the same file

class AClass(object):

    def method(self, *args, **kwargs):
        return None

module.attribute

  • the definiton in module.py

    attribute = None
    
  • how to use in a different file

    import module
    
    module.attribute
    

module.function()

  • the definiton in module.py

    def function():
        return None
    
  • how to use in a different file

    import module
    
    module.function()
    

module.function(*args, **kwargs)

  • the definiton in module.py

    def function(*args, **kwargs)
    
  • how to use in a different file

    import module
    
    module.function(*args, **kwargs)
    

module.AClass.attribute

  • the definiton in module.py

    class AClass(object):
    
        attribute = None
    

how to use in a different file

import module

instance = module.AClass()
instance.attribute
  • or the definition in module.py

    class AClass(object):
    
        def __init__(self, attribute):
            self.attribute = attribute
    

    how to use in a different file

    import module
    
    instance = module.AClass(attribute='Attribute')
    instance.attribute
    

module.AClass.method()

  • the definiton in module.py

    class AClass(object):
    
        def method(self):
            return None
    
  • how to use in a different file

    import module
    
    instance = module.AClass()
    instance.method()
    

module.AClass.method(*args, **kwargs)

  • the definiton in module.py

    class AClass(object):
    
        def method(self, *args, **kwargs):
            return None
    
  • how to use in a different file

    import module
    
    instance = module.AClass()
    instance.method(*args, **kwargs)