Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107741 > unrolled thread
| Started by | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| First post | 2016-04-28 12:07 +1000 |
| Last post | 2016-04-28 12:07 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Pythonic style (was: Differences between Class(Object) and Class(Dict) for dictionary usage?) Ben Finney <ben+python@benfinney.id.au> - 2016-04-28 12:07 +1000
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2016-04-28 12:07 +1000 |
| Subject | Pythonic style (was: Differences between Class(Object) and Class(Dict) for dictionary usage?) |
| Message-ID | <mailman.159.1461809287.32212.python-list@python.org> |
Christopher Reimer <christopher_reimer@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
Back to top | Article view | comp.lang.python
csiph-web