new function 'limit' to limit the number of iterations
This commit is contained in:
parent
65a8470335
commit
9e6153a16c
1 changed files with 10 additions and 2 deletions
|
|
@ -24,7 +24,7 @@ import types
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['get_backtrace', 'get_bytes_size', 'html2text', 'iter_fields',
|
__all__ = ['get_backtrace', 'get_bytes_size', 'html2text', 'iter_fields',
|
||||||
'local2utc', 'to_unicode', 'utc2local']
|
'local2utc', 'to_unicode', 'utc2local', 'limit']
|
||||||
|
|
||||||
|
|
||||||
def get_backtrace(empty="Empty backtrace."):
|
def get_backtrace(empty="Empty backtrace."):
|
||||||
|
|
@ -107,3 +107,11 @@ def utc2local(date):
|
||||||
date = date.replace(tzinfo=tz.tzutc())
|
date = date.replace(tzinfo=tz.tzutc())
|
||||||
date = date.astimezone(tz.tzlocal())
|
date = date.astimezone(tz.tzlocal())
|
||||||
return date
|
return date
|
||||||
|
|
||||||
|
def limit(iterator, lim):
|
||||||
|
count = 0
|
||||||
|
iterator = iter(iterator)
|
||||||
|
while count < lim:
|
||||||
|
yield iterator.next()
|
||||||
|
count += 1
|
||||||
|
raise StopIteration()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue