In your code, the xml_wrapper
is a decorator which takes a function, then wraps it with another function (wrap
) and returns it. The function wrap
does not take any argument(as in your code). But when you call xml.data_dictionary
, python is implicitly passing the instance xml
(known as self
) which is causing the problem. May be this is what you want:
>>> class Xml(object):
def __init__(self, data_dictionary=None):
self.data_dictionary = data_dictionary
def xml_wrapper(f):
def wrap(*k,**kw):
xml_msg = f(*k,**kw)
return '<?xml version="1.0" encoding="UTF-8"?>\n'+xml_msg['name']
return wrap
@property
@xml_wrapper
def data_dictionary(self):
return self._data_dictionary
@data_dictionary.setter
def data_dictionary(self, data):
self._data_dictionary = data
>>> xml = Xml()
>>> xml.data_dictionary = {"name":"name 1"}
>>> print xml.data_dictionary
<?xml version="1.0" encoding="UTF-8"?>
name 1
This time xml_wrapper is taking a function (data_dictionary
) then calls this function to get the xml_msg
(inside wrap
). wrap
now takes arbitrarily many arguments and just passes those to original function (data_dictionary
), takes the value, formats it, and returns.