Python imitate class's constructor only using function dynamically -
this little bit weird. want dynamic initialize part of function's parameters before call it. don't want use class reason. let's have function:
def inner(a,b,c): "a,b,c something" return result before formally call it, i'd initialize somewhere:
partinitalabc=inner(,b,c) then i'll use as:
result=partinitialabc(a) please notice want dynamically. when initial class using constructor, decorator may not appropriate @ time...
any 1 have idea?
it sounds you're looking functools.partial:
return new
partialobject when called behave func called positional arguments args , keyword arguments keywords.
if pass arguments partial positional arguments, they'll appear @ beginning of argument list, isn't want. keyword arguments give more control on parameters passed:
partinitialabc = functools.partial(inner, b=b_value, c=c_value);
Comments
Post a Comment