Skip to main content

Automatic creation of self properties from parameters.

Project description

auto_self_params

A python package to automatically assign parameters to self. This enables replacing code such as:

class A:
    """ Typical Code. """
    def __init__(self, param1, param2, kwparam1=0, kwparam2=0):
        """ Create Example Class."""
        self.param1 = param1
        self.param2 = param2
        self.kwparam1 = kwparam1
        self.kwparam2 = kwparam2
        # etc.

With code more like:

from auto_self_params import auto_self_params

class A:
    """ Revised Code. """
    def __init__(self, param1, param2, kwparam1=0, kwparam2=0):
        """ Create Example Class."""
        auto_self_params(locals())  # Assign all parameters to self
        # etc.

Only use this package if you need the paramters passed to __init__ to produce matching names in self when called.

You can, however, create a dictionary with locals and remove unwanted paramters before passing it to auto_self_params so as to exclude unwanted parameters.

Note that this cannot yet be used with the: def __init__(self, *args, **kwargs): format.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_self_params-0.0.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

auto_self_params-0.0.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page