Skip to content

Commit

Permalink
Merge pull request #34 from jwegan/patch-2
Browse files Browse the repository at this point in the history
Add one line initializer
  • Loading branch information
yasoob committed Aug 18, 2015
2 parents 386360e + 56cc151 commit 0e089cb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions one_liners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,17 @@ is a simple example:
print(list(itertools.chain.from_iterable(a_list)))
# Output: [1, 2, 3, 4, 5, 6]
**One Line Constructors**

Avoid a lot of boilerplate assignments when initializing a class

.. code:: python
class A(object):
def __init__(self, a, b, c, d, e, f):
self.__dict__.update({k: v for k, v in locals().items() if k != 'self'})
A couple of more one liners can be found on the `Python
website <https://wiki.python.org/moin/Powerful%20Python%20One-Liners>`__.

0 comments on commit 0e089cb

Please sign in to comment.