Sorry for the confusing title because I really don't know how to describe this question. I will try to use an example to explain.
Say I want to write a class
class Line:
def __init__(self, x1, y1, x2, x3):
self.start = (x1, y1)
self.end = (x2, y2)
def length(self, metric):
# return the length of this line using the input metric
Here metric is a metric on the plane (it might be a function, or a table etc, not important here)
Now I want to do something like
def findLine(metric):
l1 = Line(0,0,1,1)
l2 = Line(0,0,2,2)
# just an example, I may need to create a lot of lines then compare their length
if l1.length(metric)>l2.length(metric):
return l1
I am looking for a way that somehow setting a default value for metric for all the lines used in findLine
so I can simply call l1.length()>l2.length() in findLine.
Also, the data metric might be stored in a large data frame. I think it might be not good to store them in each line.
Sorry for the confusing. I am just trying to find a way to simplify my code.
I should add that in my code, there are 5 or 6 these kind of parameters not just one.
That's the reason I want to find a way to not writing all parameters every time.
Thanks!
def length(self, metric='xxx'):?data metric might be stored in a large data frame, but if everyLinehas its own reference to it, you only increaseLineby an additional reference, and not by the size of thelarge data frame.