Access contents in base class from derived class

 Define the methods inside base class

Call the base class __init__ method from derived class using super().__init__ method

Access the method or values in base class using self. keyword.

Example


from typing import Optional, Dict, List, Tuple, Union
import argparse
class computer:
    def __init__(self,input_args:Optional[List[str]]):
        #self.a=a
        #self.b=b
        #self.c=c
        #print(f'base class {a}')
        #print(f'base class  {b}')
        #print(f'base class {c}')
        #self.add(self.a,self.b)
        self._parse_arguments(input_args)
    #def add (self,a,b) :
        #print(a+b)   
    def _parse_arguments(self,input_args:Optional[List[str]]):

        parser = argparse.ArgumentParser(

        prog=' Processing Job',

        description='Run a  processing job',

        epilog='Contact xxx@riotinto.com for more information.'

        )

        parser.add_argument('-dm''--data_movement_id',

                            required=Truetype=inthelp='The DataMovementId')

        parser.add_argument('-b''--batch_id'required=True,

                            type=inthelp='The BatchId')

        parser.add_argument('-s''--support_db'required=True,

                            help='The name of the linked service to ')

        if input_args is None:

            args = parser.parse_args()

        else:

            args = parser.parse_args(input_args)

        self._batch_id = args.batch_id

        self._data_movement_id = args.data_movement_id

        self._support_db_ls_name = args.support_db

        #print(self._batch_id,self._data_movement_id,self._support_db_ls_name)

class memory(computer):
    
    def __init__(self,*args):
        print('derived'
        
        super().__init__(*args) 
        print(self._batch_id,self._data_movement_id,self._support_db_ls_name)
data_movement_id = 100000000000002         
m=memory(f"-dm {data_movement_id} -b 100000000000145 -s LS_ASQL_SUPPORT_DB".split())        


Comments

Popular posts from this blog

Introduction To Oracle10g

Insert

Except