擅长:python、mysql、java
<blockquote>
<p>errors = list() # How do I say it that it is directly of the ErrorDefinition() type, to not import it every time that I'm going to append an error definition?</p>
</blockquote>
<p>我不确定你在评论中想说什么,但如果我理解正确,最好的接近方法是定义一个方法来添加一个错误。</p>
<pre><code>class ResponseDTO(object): # New style classes are just better, use them.
def __init__(self):
self.success = True # That's the idiomatic way to define an instance member.
self.errors = [] # Empty list literal, equivalent to list() and more idiomatic.
def append_error(self, code, message, exception):
self.success = False
self.errors.append(ErrorDefinition(code, message, exception))
</code></pre>