I want to call a function that takes a class as an argument, without passing it a class.
The function only uses an integer value from the class, and the place I call it from has information that can calculate the value independently.
My code looks like:
Function I want to call:
def buckets_from_pairs(fs_pairs,par):
fsea=fermi_sea(par.N)
# rest of function has no reference to par
Function I call from:
def deltas(roots):
if "buckets" in roots:
# do function on roots["buckets"]
if "partition" in roots:
#somehow define value such that value.N=len(roots["roots"])
buckets=buckets_from_pairs(roots["partition"], value)
#do function on buckets
I could change deltas to take par as an argument and I could change buckets_from_pairs to work without par but both would require a lot of reworking, and I would have to organise it with my supervisor who wrote both functions (he doesn’t have this problem).
So I was hoping there was a simpler way of creating an object that can use the “dot” to reference something than creating a new class in the calling function.
1 Answer