Я пытаюсь получить доступ к объекту, который был передан моей функции (определенной в моем классе).
- По сути, я вызываю функцию
publish_alert
, определенную внутри класса AlertPublishInterface
.
- вызывающий передает в
publish_alert
экземпляр класса с именем AlertVO
- как только я получаю этот переданный экземпляр аргумента через
publish_alert
, я просто пытаюсь получить доступ к членам данных экземпляра переданного аргумента внутри класса AlertPublishInterface
(в котором определена вызываемая функция publish_alert
.
Я получаю AttributeError
на шаге 2, то есть при доступе к членам экземпляра переданного аргумента как:
AttributeError: Экземпляр AlertPublishInterface не имеет атрибута 'alert_name'
Вот фрагмент кода:
Файл AlertPublishInterface:
import datetime
import logging.config
import django_model_importer
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('alert_publish_interface')
from alert.models import AlertRule #Database table objects defined in the model file
from alert.models import AlertType #Database table objects defined in the model file
import AlertVO #This is instance whose members am trying to simple access below...!
class AlertPublishInterface:
def publish_alert(o_alert_vo, dummy_remove):
print o_alert_vo.alert_name #-----1----#
alerttype_id = AlertType.objects.filter(o_alert_vo.alert_name,
o_alert_vo.alert_category, active_exact=1) #-----2----#
return
AlertVO определяется как:
class AlertVO:
def __init__(self, alert_name, alert_category, notes,
monitor_item_id, monitor_item_type, payload):
self.alert_name = alert_name
self.alert_category = alert_category
self.notes = notes
self.monitor_item_id = monitor_item_id
self.monitor_item_type = monitor_item_type
self.payload = payload
фрагмент кода вызова (который вызывает функцию AlertPublishInterface
publish_alert
):
from AlertVO import AlertVO
from AlertPublishInterface import AlertPublishInterface;
o_alert_vo = AlertVO(alert_name='BATCH_SLA', alert_category='B',
notes="some notes", monitor_item_id=2, monitor_item_type='B',
payload='actual=2, expected=1')
print o_alert_vo.alert_name
print o_alert_vo.alert_category
print o_alert_vo.notes
print o_alert_vo.payload
alert_publish_i = AlertPublishInterface()
alert_publish_i.publish_alert(o_alert_vo)
Однако, это терпит неудачу в строках, отмеченных # ----- 1 ---- # и # ----- 2 --- # выше с ошибкой типа, кажется, что это связывает объект AlertVO
(o_alert_vo
экземпляр) с AlertPublishInterface
классом:
полный блок вывода экрана при запуске:
python test_publisher.py
In test_publisher
BATCH_SLA
B
some notes
actual=2, expected=1
Traceback (most recent call last):
File "test_publisher.py", line 17, in
alert_publish_i.publish_alert(o_alert_vo.alert_name)
File "/home/achmon/data_process/AlertPublishInterface.py", line 26, in publish_alert
print o_alert_vo.alert_name
<b>AttributeError: AlertPublishInterface instance has no attribute 'alert_name'</b>
Не могу избавиться от вышеуказанной ошибки после долгих поисков ... может кто-нибудь помочь ...?
Спасибо ...! (Тоже срочно ...!)