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.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.
If you would like to use the:
def __init__(self, *args, **kwargs):
format then you may wish to use a pattern such as:
from auto_self_params import auto_self_params
class A:
""" Revised Code. """
def __init__(self, *args, **kwargs):
""" Create Example Class."""
param_dict = {'self': self, 'args': args, **kwargs}
auto_self_params.auto_self_params(param_dict) # Assign parameters to self
# etc.
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for auto_self_params-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28f77a1cb5b505123dcd45bb4a429921646a27b1358e581bbe9bdbe01e0fbfb2 |
|
MD5 | 1be1c415e99eea85b40f178cc3453e71 |
|
BLAKE2b-256 | d557dfc61eb1167b2e1d4f513715652263e6ebf0650b29fa09c0af34d9e9775e |