from shapely.geometry import Point
def somefunc(lst):
return [Point(x) for x in lst]
if __name__ == "__main__":
xy = [(x, x) for x in range(1, 10)]
print(somefunc(xy))
There is a need to add a count variable to somefunc in this state,
def somefunc(lst, count=False):
zz = [Point(x) for x in lst]
if count:
return [(id,x) for x in enumerate(zz)]
return zz
I changed it like this.
Is there a way to support the count without touching some func?
Thank you.
python
Please refer to the following.
import functools
def insert_count(count):
def decorator(func):
@functools.wraps(func)
def _wrap(*args, **kwargs):
zz = func(*args, **kwargs)
if count:
return [(id,x) for x in enumerate(zz)]
return zz
return _wrap
return decorator
from shapely.geometry import Point
@insert_count(True)
def somefunc(lst):
return [Point(x) for x in lst]
result = somefunc(zip(range(1, 11), range(1, 11)))
© 2025 OneMinuteCode. All rights reserved.