This is a collection of common tools to use across projects. It current passes all tests for python v3.7, v3.8, v3.9. Python v3.6 is not supported.
formatting
: This module includes a number of type conversion functions as well as functions to format, read and write type hinted dataclasses.method_helpers
: This module provides some convenience function to read and write from a dataclass to a pipe delimited file.
The formatting functions are broadly separated into several groups and build upon one another going down.
get_ga_types
: Standardized call to get base and argument types from atyping.Generic
.get_dc_type_hints
: Customized version oftyping.get_type_hints
.
fmt_bool
: Formats known boolean value to specified format.fmt_float
: Formats known float value to specified format.fmt_int
: Formats known integer value to specified format.fmt_none
: Formats known None value to specified format.fmt_str
: Formats known string value to specified format.fmt_dict
: Formats known dictionary value to specified format.fmt_list
: Formats known list value to specified format.fmt_set
: Formats known set value to specified format.fmt_tuple
: Formats known tuple value to specified format.fmt_value
: Using dynamic typing, it then calls the relevant function above to format value to specified format.fmt_dataclass
: Formats dataclass values to type hints specified in its definition.
str2list
: Standardizes string or list input to list of string.val2txt
: Converts generic input to text suitable for writing to text file.txt2val
: Attempts to guess type of a text string within a limited set of types.process_container
: Standardizes string, list, dataclass or list of dataclasses to a list of dataclass including defining the dataclass based on the sequence of values in the list.define_dataclass
: Populates a dataclass instance taking its values from a second class.
These applications grew from supporting namedtuples
to dataclasses
. They can and will be cleaned up in the future to reduce redundancy.
read_txt
: Usingtxt2val
it reads in a list of strings and returns a list of values using guessed types.write_txt
: Usingval2txt
it reads in a list of various formatted values from a dataclass and returns a list of strings.write_txt_class
: Usingval2txt
it returns a list of strings defined by the variables defined by the namedtuple or dataclass whose values are taken and reformatted from a second namedtuple or dataclass.write_txt_row
: This function behaves likewrite_txt_class
if the dest_class is specified and likewrite_txt
if it is not specified.
The following helpers were developed in applications where a parent class holds a set of instances of a dataclass in a dictionary for organization, updating, and maintenance.
__unixpipe
: This defines an internal default csv dialect that is pipe delimited.base_read_file
: This reads from the specified ASCII file using the parameters for identifying and processing each record type into the given dataclass. It returns total number of records read from the file.base_write_file
: This writes to the specified file file from a dictionary reference to a set of dataclass instances. It returns total number of records written to the file.base_read_xls
: This reads from the specified XLS file using the parameters for identifying and processing each record type into the given dataclass. Its call is intended to be nearly transparent with calling thebase_read_file
using the same parameters. It returns total number of records read and number of records read by record type.base_read_xlsx
: This reads from the specified XLSX file using the parameters for identifying and processing each record type into the given dataclass. Its call is intended to be nearly transparent with calling thebase_read_file
using the same parameters. It returns total number of records read and number of records read by record type.base_add_item
: Iterates over a general container, creates an instance of the destination class and adds the instance to a specified dictionary using the given key. It returns a list of all keys added to aid subsequent processing.