The scattr Python package
The scattr package has one function, scattr,
that provides an easy way to
Set Class ATTRibutes of classes derived
from pre-existing Python classes.
The scattr function takes
- a class object and
- the name of a helper script
and returns a subclass called
SubClassAttributesthat contains the methods defined in the helper script.
Essentially, this is an easy way to add user-defined functions to classes.
Class variables, method and classes can be added dynamically:
import pandas as pd
import math
# add pi to a pandas DataFrame
pd.DataFrame.pi = math.pi
The scattr package provides a cleaner way to
add new attributes, because it creates a new subclass and
uses method and class defined in a separate helper script.
The scattr function only adds
callable objects(methods and classes), not variables.
Pandas DataFrame example
import pandas as pd
from scattr import scattr
# create a new class that inherits from pd.DataFrame
# and includes methods defined in a 'helper.py' file
ScattrFrame = scattr(cls=pd.DataFrame, src='helper')
# instantiate the new class
df = ScattrFrame(data=pd.read_csv('risk_factors_cervical_cancer.csv'))
# test methods added from helper file
df.say_hi()
# test CowClass added from helper file
df.CowClass.say_moo()
# test method from parent class
df.head(n=1)
# confirm that df is an instance of pd.DataFrame and PydyFrame
isinstance(df, (pd.DataFrame, ScattrFrame))
# confirm that ScattrFrame is a subclass of pd.DataFrame
issubclass(ScattrFrame, pd.DataFrame)
Metadata
Release files for scattr 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scattr-0.0.1.tar.gz | 2.1 kB | Without provenance | Details for scattr-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scattr-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for scattr-0.0.1-py3-none-any.whl |
Total release size: 4.4 kB
Release files / scattr-0.0.1.tar.gz
| Download URL | scattr-0.0.1.tar.gz |
|---|---|
| Size | 2.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d920b3b56342a9abea603068844572f95c437943f0f5c4c991d7284540a6d6ae
|
|
BLAKE2b-256 checksum How to use checksums |
a828a6c69e338098553d2566636687e968046c6a704700487ce885b84b32e395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Release files / scattr-0.0.1-py3-none-any.whl
| Download URL | scattr-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdfbb75f73cb97af032aaa9bda8dac3f4f1c102194d757155fbcee7806530b01
|
|
BLAKE2b-256 checksum How to use checksums |
388bd36fc549f998ff9745ab3cbc247f575f826448d26cde4963bb73df655883
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Security for scattr 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.