Collection of generic-purpose and stand-alone functions
Project description
Collection of generic-purpose and stand-alone functions
This package provides a collection of generic-purpose and stand-alone functions that are used in multiple places of Lyncs.
Installation
The package can be installed via pip
:
pip install [--user] lyncs_utils
Documentation
Here the list of functions implemented with a short description. Use help(lyncs_utils)
for more details.
Class Utils
Functions and decorator for classes. See lyncs_utils.class_utils
.
@add_to
: Decorator for adding a function to a class@add_kwargs_of(fnc)
: Decorator for adding kwargs of a function to another@compute_property
: Decorator for computing a property once and cache the result@static_property
: Decorator for a static property (like staticmethod)@class_property
: Decorator for a class property (like classmethod)call_method(obj, fnc, *args, **kwargs)
: Calls a method of the obj.default_repr_pretty
: Default method to use for repr_pretty
Extensions
Extensions of Python standard functions. See lyncs_utils.extensions
.
count
: See itertools.count. Adds call methodredirect_stdout
: See contextlib.redirect_stdout. Now, it redirects stdout also from CFreezableDict
: Extension of dict. A dictionary that can be frozen at any moment.cache
: Enables functools.cache for all versions of Python
Factors
Factorization utils. See lyncs_utils.factors
.
prod(arr)
: Enables math.prod for all versions of Pythonfactors(n)
: Returns the list of factors of nprime_factors(n)
: Returns the list of prime factors of n
Functools
Tools for functions. See lyncs_utils.functools
.
is_keyword(key)
: Whether key can be used as a function keywordget_varnames(fnc)
: Returns the list of varnames of the functionhas_args(fnc)
: Whether the function uses *argshas_kwargs(fnc)
: Whether the function uses **kwargsapply_annotations(fnc, *args, **kwargs)
: Applies the annotations of fnc to the respective *args, **kwargsselect_kwargs(fnc, *args, **kwargs)
: Calls fnc passing *args and ONLY the applicable **kwargs
I/O
Tools for I/O. See lyncs_utils.io
.
@open_file
: Decorator that opens the file (if needed) before calling the functionread(fname/fp)
: Reads data from filewrite(fname/fp)
: Writes data into the fileread_struct(fname/fp, format)
: Reads a structure from filewrite_struct(fname/fp, format, *data)
: Writes a structure from filefile_size(fname/fp)
: Returns the file sizeto_path(fname/fp)
: Reaturns a Path object to the file
Logical
Functions returning or manipulating logical values (boolean). See lyncs_utils.logical
.
single_true(iter)
: Whether one and only one element of the list is Trueisiterable(obj)
: Whether the object is iteragle or notinteractive()
: Whether Python has been run in interactive modeversion(num, pkg)
: Compares the version number to the one of a package
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.