Skip to main content

A Python Package to make life ez for pythonistas

Project description

ez_life

The objective of ez_life is to make coding with Python easier by removing repetitive code while still maintaining the same level of functionality

Installation

pip install -U ez_life

param2attr

  • Here is a little sneak peak of what you can do with this package!
    • First consider this code block:
from ez_life import Param2attr

class Foo:
	def __init__(self, param1 = None, param2 = None, param3 = None):
		# This sux
			self.param1 = param1
			self.param2 = param2
			self.param3 = param3
  • We can instead create a class that looks like this, using a property decorator to perform the param to attribute assignments
class Foo:
	@Param2attr(exclude=None) 
	def __init__(self, param1 = None, param2 = None, param3 = None): 
		# this good, allows u to write other code here during initialization 
		pass
  • If you are interested to learn about the implementation or other features that param2attr supports, feel free to read the documentation

JTProperty

  • Ez_life can also manage variable dependencies, building upon the @property decorator!

  • First here's some code with the classic @property decorator:

class SetAndGet:
  def __init__(self, r = 1):
    # initialise the protected variable
    self._radius = None

    # calls the @radius.setter method
    self.radius = r
  @property
  def radius(self):
    if self._radius is None:
      self.radius = 2
    return self._radius
  @radius.setter
  def radius(self, r):
    if r <= 0:
      raise ValueError("radius should be greater than 0")
    self._radius = r
  • Using the @JTProperty decorator, we can see that we can abstract away the self._radius variable and hence write less code!
from ez_life import JTProperty

class JTSetAndGet:
  def __init__(self, r = 1):
    self.radius = r
  @JTProperty(setter = True)
  def radius(self):
    return 2

  @radius.setter
  def radius(self, r):
    if r <= 0:
      raise ValueError("radius should be greater than 0")
    return r
  • JTProperty also supports a variety of other features including:
    • Automatic setter creation
    • Graph Dependencies
      • Support for inheritence
  • Read the documentation here to learn about these features!

ez_life directory layout:

  • ez_life: the package containing all .ipynb dev files and converted .py files
    • param2attr.ipynb: dev notebook for automation of parameter creation to class object attributes
    • param2attr.py: param2attr.ipynb -> param2attr.py via Makefile
    • jt_property.ipynb: dev notebook for more writing dependency related code
    • jt_property.py: jt_property.ipynb -> jt_property.py via Makefile
  • .gitignore: for ignoring files when pushing and pulling
  • LICENSE: what u can and can't do with this repo
  • MAKEFILE: automated test cases and .ipynb to .py conversion
  • README: this file essentially
  • test*.py: test files for modules within ez_life

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

ez-life-1.0.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

ez_life-1.0.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file ez-life-1.0.2.tar.gz.

File metadata

  • Download URL: ez-life-1.0.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for ez-life-1.0.2.tar.gz
Algorithm Hash digest
SHA256 3152937edc2f20efd04ec9a643a1a34e1aabafe62788baaadae0dbdd01e8279b
MD5 0366579764c636b1839979809bd117f3
BLAKE2b-256 e372e579de45cb0c3b43dbe2763ae42e1902689e38a6030c1a0ab61f256abd84

See more details on using hashes here.

File details

Details for the file ez_life-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: ez_life-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for ez_life-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea4c6b5c4ccc2d9f4e3bdf85909d97c8fb41c3564c32e7746a125620f16a40f
MD5 6e160b1229c6819e29f298a35e70c03a
BLAKE2b-256 2c2b5a9202baec4604483962482038eb8e7534a38bf811a7aaf89ed577306c9f

See more details on using hashes here.

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