Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How I can fill class members?
If I set the class fields in the __init__ method, they will be set in every time when object is created, which is incorrect. At that not all classes have method __init__ (for example, singleton).

class _AbstractInserter(metaclass=ABCMeta):
    TABLE_NAME: str
    MAPPING = _AbstractInserter._create_mapping()
    CODE_SQL = _AbstractInserter._create_code_sql()
    def _create_mapping(cls) -> dict:pass
    def _create_code_sql(cls) -> str:
        code_sql = ''
        for key, value in cls.MAPPING.items():
            code_sql += key + '=' + value
        return code_sql

class MyInserter(_AbstractInserter):
    TABLE_NAME = 'MyTable'

    def _create_mapping(cls) -> dict:
        mapping = {}
        mapping[cls.TABLE_NAME] = 'id'
        return mapping
MAPPING = _AbstractInserter._create_mapping() NameError: name '_AbstractInserter' is not defined
I get this error even if I use this code:
from __future__ import annotations
How can I do this?

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Call a varaible from class in the parent class Clement_2000 1 309 May-09-2019, 11:14 PM
Last Post: michalmonday
  Get variable from class inside another class hcne 3 264 Mar-30-2019, 03:02 PM
Last Post: ichabod801
  Learn to use a JSON file to fill out Template Automatically Srotkowitz 1 203 Mar-06-2019, 08:15 PM
Last Post: Larz60+
  Why Can't I call base class function for my derived class object? AmirAB 2 285 Feb-13-2019, 03:04 PM
Last Post: snippsat
  How to fill empty values with mean SriRajesh 4 425 Jan-20-2019, 01:10 PM
Last Post: SriRajesh
  Calling a class inside other class dan789 9 515 Jan-06-2019, 02:00 PM
Last Post: dan789
  Class object instance. Link instance attribute to class. Can it be done easier. Windspar 7 530 Dec-03-2018, 11:16 PM
Last Post: Windspar
  help for Kaggle Titanic Set fill the missing Age by median age of Pclass and Sex Parthasarathi009 2 751 Nov-21-2018, 06:50 PM
Last Post: Parthasarathi009
  How to fill a web form integrating with excel praveen_Akepati 0 476 Oct-27-2018, 06:23 AM
Last Post: praveen_Akepati
  How to check if class instance exists in a list of class instance objects? sonicblind 23 2,988 May-27-2018, 05:44 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)