Python Forum
Defining multiple functions in the same def process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining multiple functions in the same def process
#5
I'm not quite sure what you are after but maybe your better of with a class ?
class External:
    def __init__(self, a, b, lval, hval, yr):
        G, E = [], []
        for i in range(len(a)):
            G.append(0 if min(b[i], hval) < max(a[i], lval)
                     else min(b[i], hval) - max(a[i], lval))
        for i in range(len(a)):
            E.append(b[i] - a[i] - G[i])

        self.E = E
        self.yr = yr

    @property
    def ratio(self):
        return max(self.E[:-self.yr])

    @property
    def index(self):
        return self.E.index(self.ratio)


L = [1.238623532, 1.315924461, 1.430787909, 0.65436604, 0.78646411, 1.551692625,
     1.143410924, 1.044302349, 1.12971696, 1.007285185, 1.009553518, 0.646888596,
     1.027950548, 0.950471257, 1.048221271, 1.070840989]
H = [1.514019069, 1.662165686, 3.098538659, 3.148539828, 2.248779234, 2.542734245,
     2.312232392, 1.855592543, 1.99976568, 1.715706499, 2.111987812, 1.74066515,
     2.038750404, 2.058942087, 2.0941254, 1.498883955]

external = External(L, H, 1.00955235351066, 2.03874956866074, 6)
print(external.ratio, external.index)
Output:
1.4649765728499204 3
Reply


Messages In This Thread
RE: Defining multiple functions in the same def process - by Yoriz - Aug-09-2020, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Defining Functions theturtleking 4 2,879 Dec-07-2021, 06:45 PM
Last Post: deanhystad
  Run multiple process using subprocess Shiri 3 3,945 Nov-28-2021, 10:58 AM
Last Post: ghoul
  Process multiple pdf files Spartan314 1 1,361 Oct-27-2021, 10:46 PM
Last Post: Larz60+
  How to call multiple functions sequentially Mayo 2 9,523 Jan-06-2021, 07:37 PM
Last Post: Mayo
Question trouble with functions "def", calling/defining them Duck_Boom 13 4,512 Oct-21-2020, 03:50 AM
Last Post: Duck_Boom
  Multiple lambda functions in zipped list not executing psolar 0 1,624 Feb-13-2020, 12:53 PM
Last Post: psolar
  naming images adding to number within multiple functions Bmart6969 0 1,948 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,705 Sep-03-2019, 09:49 PM
Last Post: woooee
  Defining functions TommyAutomagically 1 1,911 Apr-25-2019, 06:33 PM
Last Post: Yoriz
  Multiple process access to a serial port mkonnov 0 3,088 Apr-14-2019, 12:42 PM
Last Post: mkonnov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020