Python Forum
Pythonic way to handle/spread alerts class in multiple modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pythonic way to handle/spread alerts class in multiple modules
#11
Can you explain what you mean by Core -> Handler -> Class A -> Class B | Class C | .. ?

I don't see a problem in defining a module
# spamish.py

class Spam:
    def __init__(self):
        self.eggs = 'eggs'

the_spam = Spam() # <--- our unique instance
In other modules, we can simply import the unique instance
from spamish import the_spam
print(the_spam.eggs)
Reply
#12
Well,

I think I found the perfect solution to me (Didn't know this use). Just define them as class variables and classmethods decorator and the variables have the same value across all the instances:

class AlertsHandler:
    """
    Defines all the operations that are required to process all the NIMFty alerts.
    This handler uses class variables that have the same value across all class instances
    """
    alert_1 = []
    alert_2 = []
    alert_3 = []
    ...

    @classmethod
    def send_alerts(cls):
        """
        Sends alerts (emails) about the process execution

        :return: None
        """
        ...
And in my code I just:

AlertsHandler.alert_1.append(x)
AlertsHandler.send_alerts()
when I need :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to handle multiple audio uploads without canceling ongoing API requests? muba 2 945 Jan-01-2025, 01:04 AM
Last Post: Skaperen
  Can I use logging in a class (without multiple messages) mevan 2 1,321 Oct-16-2023, 11:08 PM
Last Post: mevan
  Pythonic from a C++ perspective PyDan 2 1,429 Sep-18-2023, 11:39 AM
Last Post: PyDan
  What's the best way for multiple modules to handle database activity? SuchUmami 3 1,466 Jul-08-2023, 05:52 PM
Last Post: deanhystad
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 3,067 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Is this use of exec pythonic? psolar 1 2,380 Feb-07-2020, 12:23 PM
Last Post: buran
  which is "better" (or more Pythonic)? Skaperen 2 2,842 Feb-01-2020, 03:10 PM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 7 4,534 Feb-01-2020, 03:51 AM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 8 4,881 Nov-16-2019, 06:46 PM
Last Post: Skaperen
  which is more Pythonic? Skaperen 5 3,953 Jul-16-2019, 01:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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