Python Forum
How to implement class register? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to implement class register? (/thread-16100.html)



How to implement class register? - AlekseyPython - Feb-14-2019

I write this code:
Creater.py:
from Database.Tables import Career

class Creater:
    REGISTRY = []
    
    @classmethod
    def register(cls):
        def decorator(child_class):
            cls.REGISTRY.append(child_class)
            return child_class
        
        return decorator
    .....
    .....
    def _create_table(self, table):
        return self.connection.execute(code=table.creating())
    
    def create_tables(self):   
        for table in self.REGISTRY:
            self._create_table(table)
Career.py:
from Database import Creater
from Database.Tables import _TextsQuery

@Creater.Creater.register
class CareerTexts(_TextsQuery.AbstractText):
    TABLE_NAME = 'Career'
    
    @classmethod
    def creating(cls) -> str:
        return '\
        CREATE TABLE ' + cls.TABLE_NAME + ' (\
        id         int,\
        country_id smallint,\
        city_id    smallint,\
        from_year  smallint,\
        until_year smallint,\
        position   varchar(50),\
        PRIMARY KEY(id))'
Output:
@Creater.Creater.register AttributeError: module 'Database.Creater' has no attribute 'Creater'
First, the Creator module is loaded, and as far as I understand it, the Creator module doesn’t full downloading and starts loading the Career module. Since the Creator module did not load, we get an error when loading the Career module.

What can i do?