Christopher Reimer <christopher_rei...@icloud.com> writes: > On 4/27/2016 7:33 AM, Ian Kelly wrote: > > > self.__dict__ = {'key', 'value'} > > > > self.key = value > > Which expression is Pythonic?
(Note that assignment is not an expression in Python; assigment is a statement.) > I've seen both used in various examples on the Internet. I would say the latter is more Pythonic, because it: * Better conveys the intention (“set the value of the ‘self.key’ attribute”). * Uses the built-in mechanisms of Python (don't invoke magic attributes, instead use the system that makes use of them behind the scenes). * Expresses that intention more concisely (fewer terms). * Expresses that intention more clearly (less syntactic noise). -- \ “Nothing so needs reforming as other people's habits.” —Mark | `\ Twain, _Pudd'n'head Wilson_ | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list