मैं एक वर्ग (नीचे) है:मैं इस ऑब्जेक्ट को क्यों नहीं उठा सकता?
class InstrumentChange(object):
'''This class acts as the DTO object to send instrument change information from the
client to the server. See InstrumentChangeTransport below
'''
def __init__(self, **kwargs):
self.kwargs = kwargs
self._changed = None
def _method_name(self, text):
return text.replace(' ','_').lower()
def _what_changed(self):
''' Denotes the column that changed on the instrument returning the column_name of what changed.'''
if not self._changed:
self._changed = self._method_name(self.kwargs.pop('What Changed'))
return self._changed
def __getattr__(self, attr):
for key in self.kwargs.iterkeys():
if self._method_name(key) == attr:
return self.kwargs[key]
def __str__(self):
return "Instrument:%s" % self.kwargs
__repr__ = __str__
what_changed = property(_what_changed)
मैं निम्नलिखित परीक्षण चलाते हैं:
def test_that_instrumentchangetransport_is_picklable(self):
test_dict = {'Updated': 'PAllum', 'Description': 'BR/EUR/BRAZIL/11%/26/06/2017/BD',
'Ask Q': 500, 'Bbg': 'On', 'C Bid': 72.0, 'Benchmark': 'NL/USD/KKB/7.000%/03/11/2009/BD',
'ISIN': 'XS0077157575', 'Bid YTM': 0.0, 'Bid Q': 100, 'C Ask': 72.25, 'Ask YTM': 0.0, 'Bid ASW': 0.0,
'Position': 1280000, 'What Changed': 'C Bid', 'Ask ASW': 0.0}
ins_change = InstrumentChangeTransport(**test_dict)
assert isinstance(ins_change, InstrumentChangeTransport)
# Create a mock filesystem object
file = open('testpickle.dat', 'w')
file = Mock()
pickle.dump(ins_change, file)
मैं:
Traceback (most recent call last):
File "c:\python23\lib\site-packages\nose-0.11.0-py2.3.egg\nose\case.py", line 183, in runTest
self.test(*self.arg)
File "C:\Code\branches\demo\tests\test_framework.py", line 142, in test_that_instrumentchangetransport_is_picklable
pickle.dump(ins_change, file)
File "C:\Python23\Lib\copy_reg.py", line 83, in _reduce_ex
dict = getstate()
TypeError: 'NoneType' object is not callable
मैं अचार डॉक्स देखा है, लेकिन मुझे काफी कुछ नहीं मिला है।
कोई विचार?
बेन
एक साइड नोट के रूप में: 'key.kwargs.iterkeys() में कुंजी कुंजी के माध्यम से कुंजी और खोज उत्पन्न करती है। बेहतर उपयोग 'self.kwargs' में, जो हैशटेबल लुकअप (तेज़) करने का प्रयास करता है। – ebo
कुछ डिबगिंग करने में सहायता मांगते समय, यह समस्या को पुन: उत्पन्न करने के लिए पर्याप्त कोड प्रदान करने में मदद करता है। यह आपके द्वारा पोस्ट किए गए कोड से अप्रासंगिक सब कुछ हटाने में और भी मदद करता है। –