Skip to content

Commit

Permalink
fix python2 comat
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuanshuai committed Sep 20, 2023
1 parent a10154d commit 8496f71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion zhdate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"""

from datetime import datetime, timedelta
from itertools import accumulate

from .compat import accumulate
from .constants import CHINESENEWYEAR, CHINESEYEARCODE


Expand Down
20 changes: 20 additions & 0 deletions zhdate/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding=utf-8 -*-

from __future__ import absolute_import, print_function

import operator


def accumulate(iterable, func=operator.add):
'Return running totals'
# accumulate([1,2,3,4,5]) --> 1 3 6 10 15
# accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
it = iter(iterable)
try:
total = next(it)
except StopIteration:
return
yield total
for element in it:
total = func(total, element)
yield total

0 comments on commit 8496f71

Please sign in to comment.