A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-July/054568.html below:

[Python-Dev] reducing self.x=x; self.y=y; self.z=z boilerplate code

[Python-Dev] reducing self.x=x; self.y=y; self.z=z boilerplate codeRalf W. Grosse-Kunstleve rwgk at cci.lbl.gov
Sat Jul 2 00:59:46 CEST 2005
Hi,

I often find myself writing:

  class grouping:

      def __init__(self, x, y, z):
          self.x = x
          self.y = y
          self.z = z

I hate it, and every time I show this to a Python newcomer I get that
skeptic look. How about this for a change?

  class grouping:

      def __init__(self, .x, .y, .z):
          pass

This is supposed to work the same way as:

      def __init__(self, x, y, z):
          self.x = x
          del x
          self.y = y
          del y
          self.z = z
          del z

Currently the .x syntax leads to:

      def __init__(self, .x, .y, .z):
                         ^
  SyntaxError: invalid syntax

I.e. it seems to me that there shouldn't be any backward compatibility
issues.

I'll write a PEP if I hear a few voices of support.
(Otherwise I'll stick to my "adopt_init_args" workaround:
http://phenix-online.org/cctbx_sources/libtbx/libtbx/introspection.py
which does a similar job but doesn't look as elegant and is also
quite inefficient).

Cheers,
        Ralf
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4