Documentation
Functions
cookies_utilities.get_dates
- cookies_utilities.get_dates(start='2016-07-01 02:00:00', end='2016-07-02 01:00:00', format='%Y-%m-%d %H:%M:%S', delta={'days': 0, 'hours': 1, 'minutes': 0, 'weeks': 0}, geniter=False, cast_str=True, format_out=None)
Returns a list of times from the ‘start’ time to the ‘end’ time, incremented by ‘delta’.
If you’re using the result as an iterator, it is recommended to set geniter=True.
- Parameters:
start (string) – Start time string.
end (string) – End time string (inclusive).
format (string) – Conversion format for datetime.strptime.
delta (dict) – Timedelta as args for datetime.timedelta.
geniter (bool) – Whether to return as a generator iterator (default False).
cast_str (bool) – Whether to convert output to string (default True).
format_out (string) – Conversion format for output (default same to format).
- Return type:
list (or generator iterator) of string (or datetime.datetime)
Example
An example of incrementing by one day.
import cookies_utilities as cu
dates = cu.get_dates(
start='2016/07/01', end='2016/07/03', format='%Y/%m/%d',
delta={'days': 1}, format_out='%Y-%m-%d')
print(dates)
['2016-07-01', '2016-07-02', '2016-07-03']
An example of incrementing by 20 minutes.
import cookies_utilities as cu
dates = cu.get_dates(
start='2016-07-01 02:00:00', end='2016-07-01 03:00:00',
format='%Y-%m-%d %H:%M:%S',
delta={'minutes': 20})
print(dates)
['2016-07-01 02:00:00', '2016-07-01 02:20:00', '2016-07-01 02:40:00', '2016-07-01 03:00:00']
An example of retrieving as a generator iterator.
import cookies_utilities as cu
dates = cu.get_dates(
start='2016/07/01', end='2016/07/03', format='%Y/%m/%d',
delta={'days': 1}, geniter=True)
print(type(dates))
for date in dates:
print(date)
<class 'generator'>
2016/07/01
2016/07/02
2016/07/03
Classes
cookies_utilities.Stopwatch
- class cookies_utilities.Stopwatch
Stopwatch for measuring processing time.
- press(key='')
Press the stopwatch.
- Parameters:
key (string) – The idenficator for the time (optional).
- show()
Show lap times.
Example
import cookies_utilities as cu
sw = cu.Stopwatch()
sw.press('train start')
# train
sw.press('train end')
# test
sw.press('test end')
sw.show()
time1(train start-train end): 2.000s
time2(train end-test end): 1.000s
total: 3.000s