Package: pycamia
pycamiaIntroductionpycamiais the base package affiliated to projectPyCAMIA. It is a collection of different useful tools necessary in python programming.pycamiawas designed forpython v3.6+. It is consist of the following sub-packages.environmentis a package containing functions to inspect the context. e.g. get the local variables in the context that calls a function.stropis a collection of advanced functions for strings. e.g. tokenize a string by spliting outside brackets OR find all indices for matched sub-strings.listopis a collection of advanced functions for lists. e.g. flatten a nested list.manageris a package to manage file and package infos. e.g. easily check the dependencies OR easy update the version.functionsis a package of special (and commonly trivial) functions. e.g. empty functions.exceptionsis a package to handle exceptions. e.g. touch a function and suppress the error OR assert with comment OR quickly create an Error.inoutis a package to extend the input/output. e.g. printing to a string OR suppressing the console output.timingis a package to time the executions. e.g. usewithstructure to record time spent for a set of commands.moreis a collection of uncategorized functions, one need to import them frompycamia.more.InstallationThis package can be installed bypip install pycamiaor moving the source code to the directory of python libraries (the source code can be downloaded ongithuborPyPI).pipinstallpycamiaPackageenvironmentThis package fetches the surrounding environment of the call. It is likely that no more functions would be added to it. If there's any suggestion, please contact the developer.Usev = get_environ_locals()orv = get_environ_globals()to get the dictionary of local or global variables in the parent environment. If the result is out of expectations, please contact the developer.Usev['name']to read variablenameandv['name'] = valueto add variable to the environment.PackagestropThis package cope with str objects.Usestr_lento find the ASCII length for a string, with a length2for wide characters.Usestr_sliceto slice a string by given indices.Usefind_allto obtain all the indices of a given string.str_slice(s, find_all(s, k))is equivalent tos.split(k).Usesorted_dict_reprto create a repr string for a dictionary with ordered key.Useenclosed_objectto find the first object enclosed by brackets.Usetokenizeto split a string without breaking enclosed objects. This is useful in breaking text of dictionary structures or arguments. e.g. one can usetokenize(args, sep=[',', '='])[::2]to find the argument names ifargsis a string in the formatkey1=value1, key2 = value2, ....PackagelistopThis package cope with list objects. More useful functions will be added to it in the future.Useargmin(list, domain)to find the indices for the minimal value in list. The function only search in the indicesdomain. A list is output as there may be multiple entries.Useargmaxto find the indices for the maximal value, similar toargmin.Useflatten_listto unwrap the list elements to create a list with no element in typelist.Useprodto obtain the product of all numbers in the list.Useitemto fetch the only element in the list. An error will be raised if there isn't any or are more than 1 elements.PackagemanagerThis package manages the info of packages and files. One can use it to organize the project.Use__info__ = info_manager(project="PyCAMIA", ...)to list the properties at the front of files. This serve as a brief introduction to readers.Useinfo_managerat the beginning of__init__.py,pack.pyuses it to create the portrait of a package.Use__info__.check_requires()to automatically check if the dependencies in attributerequiresexist or not. This is commonly used in__init__.py. One can use__info__ = info_manager(...).check()to perform an in-place check.Usewith __info__:before importing required dependencies as well to perform a double check.PackagefunctionsThis package contains simple functions. It is the simplest package in the project so far.Useempty_functionfor a function that does nothing. One can put any argument to the function but nothing would happen.Useconst_function(a)for a function that accepts any argument but does nothing and always returna.PackageexceptionsThis package handles exceptions.Usetouch(function)to try a function and suppress the error in the mean time. e.g.touch(lambda: 1/a)returnsNoneto tell you that an exception occurs whena=0, but returns1whena=1.Usecrashed(function)to check whether a function fails or not.Useavouch(bool_to_be_tested, assertion_text)to avouch that the given expression is true and output your designedassertion_textwhen the test fails.UseError("name")to creat a new error type. It is the same as creating an Error tag byclass nameError(Exception): pass.PackageinoutThis package manipulates the input/output. Currently, it only deal with print. Shell handler or other inout functions will be added here in the future.Usewith no_print:to suppress the console output. Although not recommended, one can usewith no_print as out_stream:andoutput = str(out_stream)inside thewithstructure to fetch the output.Usesprint = SPrint()to create a functionsprintthat collects the printed text. Useout = sprint()orsprint.textto get the results.PackagetimingThis package use the time spent of commands to perform useful inspection or organization of the codes.Use@time_thisto time a function.Usewith Timer("name"):to time a series of commands.Usewith scope("name"):to nest a series of commands. It is an alias ofTimer.Usewith scope("name"), jump:to jump a series of commands.Usewith scope("name"), Jump(False):to disable the jump.Usewf = Workflow("step1", "step2")andwith wf("step1(2)"), wf.jump:before commands of "step1(2)" to create a workflow. One can change the arguments in the init function to decide which steps to run.Use@periodic(seconds, max_repeat)to run a function repeatedly.PackagemoreCurrently, onlyonceis contained in themorepackage.
Adding it in a function to check if the function is run once or not.Waiting to Be ImrovedMore functions will be added in the future, including path handler, tools for shell and so on.Contact us to make suggestions.Acknowledgment@Yuncheng Zhou: Developer