Python Forum
How to implement class register?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to implement class register?
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pymodbus Write value to register stsxbel 10 8,058 Aug-18-2022, 01:42 PM
Last Post: DeaD_EyE
  Right way to implement interfaces yossiy123 1 1,266 May-12-2022, 10:31 AM
Last Post: Gribouillis
  Simple syntax to asynchronously get access to MODBUS register orion67 1 2,833 Jan-22-2022, 12:40 PM
Last Post: orion67
Question best way to implement algorithm hamidze 3 2,204 Feb-27-2021, 07:10 PM
Last Post: hamidze
  Login and Register system finndude 1 2,386 Apr-24-2020, 10:05 PM
Last Post: deanhystad
  AttributeError: 'Register' object has no attribute 'bit_7' colt 1 1,988 Dec-12-2019, 09:39 PM
Last Post: micseydel
  simple register code aocii 2 2,620 Dec-22-2018, 11:15 AM
Last Post: aocii
  Python script runs on startup but does not register keystrokes. mericanpi 3 3,419 Sep-07-2018, 02:58 PM
Last Post: mericanpi
  Correct way to implement immutable class QueenSveta 3 7,546 Jun-20-2018, 07:34 PM
Last Post: snippsat
  Why does pyinstaller register success with py to exe, but? Pleiades 1 4,276 May-09-2018, 11:02 AM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020