Skip to content

haaksmash/pyutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Utils

image

Sometimes you write a function over and over again; sometimes you look up at the ceiling and ask "why, Guido, why isn't this included in the standard library?"

Well, we perhaps can't answer that question. But we can collect those functions into a centralized place!

Provided things

Utils is broken up into broad swathes of functionality, to ease the task of remembering where exactly something lives.

enum

Python doesn't have a built-in way to define an enum, so this module provides (what I think) is a pretty clean way to go about them.

Once defined, use is straightforward:

math

Currently only has the multiplicative analogue of the built-in sum.

dicts

intersections, differences, winnowing, a few specialized dicts...

lists

flatten and unlisting. also flat_map!

bools

currently only provides an xor function.

dates

Mostly cool for the TimePeriod classes:

and so on and so forth. There's also a DiscontinousTimePeriod class, which stores a collection of TimePeriods.

There's also helper functions for common operations like days_ahead and days_ago, which pretty much do what they say on the tin.

objects

provides get_attr, which is really just a convenient way to do deep getattr chaining:

There's also an immutable utility, which will wrap an object and preven all attribute changes, recursively by default. Any attempt to set attributes on the wrapped object will raise an AttributeError:

You can toggle the recursive immutability by specifying the 'recursive' flag.

Installation (via pip)

pip install utils