There’s also a DiscontinousTimePeriod class, which get_containing_period ( time_period, another_time_period ) Īnd so on and so forth. overlaps ( another_time_period ) True > TimePeriod. Mostly cool for the TimePeriod classes: > from datetime import date # will also work with datetimes > time_period = TimePeriod ( date ( 2013, 5, 10 ), date ( 2013, 8, 11 )) > time_period > date ( 2013, 6, 12 ) in time_period True > other_time_period = TimePeriod ( date ( 2013, 6, 1 ), date ( 2013, 6, 30 )) > other_time_period in time_period True > another_time_period = TimePeriod ( date ( 2013, 8, 1 ), date ( 2013, 8, 30 )) > time_period. also flat_map! boolsĬurrently only provides an xor function. Intersections, differences, winnowing, a few specialized dicts… listsįlatten and unlisting. RED = 2 Traceback ( most recent call last ): File "", line 1, in File "utils/enum.py", line 114, in _setattr_ raise TypeError ( "can't set attributes on a frozen enum" ) TypeError : can 't set attributes on a frozen enum mathĬurrently only has the multiplicative analogue of the built-in sum. Once defined, use is straightforward: > Colors > Colors. # or use the enum factory (no Options, though) ColorsAlso = enum. class Options : frozen = True # can't change attributes strict = True # can only compare to itself i.e., Colors.RED = Animals.COW # will raise an exception. Enum ): RED = 0 GREEN = 1 # Defining an Enum class allows you to specify a few # things about the way it's going to behave. from utils import enum class Colors ( 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. Remembering where exactly something lives. Utils is broken up into broad swathes of functionality, to ease the task of Into a centralized place! Provided things Well, we perhaps can’t answer that question. The ceiling and ask “why, Guido, why isn’t this included in the standard Sometimes you write a function over and over again sometimes you look up at
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |