1

I'm doing Simulation of Round-Robbin algorithm and code listed below gives me error

RR.Przesuniecie[Oczekujace_procesy]
TypeError: 'instancemethod' object is unsubscriptable

Here piece of code:

class RR:
 def Przesuniecie(self, Lista):
    if(len(Lista) < 2):
        return Lista
    else:
        head = Lista[0]

        for i in range(1, len(Lista)):
                Lista[i-1] = Lista[i]
        Lista[-1] = head

        return Lista

 def Symulacja(self, n ,kwant):
        Oczekujace_procesy = []

        [....]
        if(timer == kwant):
          RR.Przesuniecie[Oczekujace_procesy]

I have no idea why it gives me error. There just piece of code, on list Oczekujace_procesy I'm doing some operations.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186

2 Answers2

3

In your method, def Symulacja(self, n ,kwant):, you are accessing Przesuniecie wrongly as RR.Przesuniecie[Oczekujace_procesy]. Przesuniecie happens to be an instance method, and not a class method, so it isn't so accessible.

You can read about the differences between the two in Difference between Class and Instance methods.

Instead, access it as self.Przesuniecie(Oczekujace_procesy)

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
1

Punctuation matters.

self.Przesuniecie(Oczekujace_procesy)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358