AnsweredAssumed Answered

Efficiently call different function based on input

Question asked by CCStormwater on Jun 11, 2013
Latest reply on Jun 13, 2013 by lpinner
I want to write my own version of "FeatureToPoint_management".  My version only needs START or END points which I pass in as a parameter.  I'd like to make the choice of methods (.startpoint or .endpoint) in an efficient manner.  An INefficient way would be to ask the question in each loop of the InsertCursor (e.g. if WhichEnd == "START": ... ).  Alternatively I could duplicate the bulk of my code and put a separate version, differing only in methods, in each branch of a big if statement (asking START|END only once, but looking redundant if not ugly).  In Perl you could actually say something like:

    point = row[0].$variable          # Where $variable has been assigned either "startpoint" or "endpoint"

(though I suppose there's still a variable lookup so perhaps that's not efficient either).

Thus I'd like to assign which method to use ( .startpoint or .endpoint) just once, and yet have none of the bulk.  My still python-young brain is drawing a blank.  Should I try (again) to understand how Lambda functions work?  (but wouldn't that still be a call to a function for every row in the loop?)