Python Forum
missing positional argument error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
missing positional argument error
#1
Hi,
I do not understand how to solve the following error which pops up when running this code: TypeError: __init__() missing 1 required positional argument: 'request'

The code:

import random
import simpy
import statistics

class DiagnosticsSimulator:
    
    def __init__(self):            
        self.nr_patients = 0 # the number of patients that arrived
        self.nr_patients_processed = 0 # the number of patients that was processed until completion
        self.nr_ultrasounds = 0 # the number of patients that received an ultrasound
        self.sojourn_time_per_patient = 0 # the average sojourn time per patient
        self.sojourn_lst = [] # list storing all sojourn times
    
    def patient(self, env, bed, receptionist, nurse, lab_assistant):
        arrival_time = env.now
        rr = receptionist.request()
        yield rr # wait for receptionist to become available
        wait_for_form = random.uniform(0.5, 1.5)
        yield env.timeout(wait_for_form) # time it takes waiting for the form
        receptionist.release()
        fill_out_form = random.uniform(15, 25)
        yield env.timeout(fill_out_form) # time it takes for filling out the form
        rr = receptionist.request()
        yield rr # wait for receptionist to become available
        return_and_brief = random.uniform(2, 4)
        yield env.timeout(return_and_brief) # time is takes to return form and receive briefing
        receptionist.release()
        br = bed.request()
        yield br # wait for bed to become available
        nr = nurse.request()
        yield nr # wait for nurse to become available
        preparation = random.uniform(2, 8)
        yield env.timeout(preparation) # time it takes to get prepared
        nurse.release()
        lr = lab_assistant.request()
        yield lr # wait for lab assistant to become available
        take_blood = random.uniform(4, 6)
        yield env.timeout(take_blood) # time it takes to take blood
        lab_assistant.release()
        if random.randint(0,100) < 30:
            nr = nurse.request()
            yield nr # wait for nurse to become available
            ultrasound = random.uniform(7, 13)
            yield env.timeout(ultrasound)
            self.nr_ultrasounds += 1
            nurse.release()
        bed.release()
        completion_time = env.now
        self.nr_patients_processed += 1
        
        sojourn_time_per_per_patient = completion_time - arrival_time # calculate the sojourntime 
        self.sojourn_lst.append(sojourn_time_per_per_patient)
        self.sojourn_time_per_patient = statistics.mean(self.sojourn_lst)
            

    def patient_generator(self, env, bed, receptionist, nurse, lab_assistant):
        while True:
            p = self.patient(env, bed, receptionist, nurse, lab_assistant) # create a new patient
            env.process(p) # start the simulation of the patient
            interarrivalTime = random.expovariate(1/6) # exponential interarrival
            yield env.timeout(interarrivalTime) # wait for the sampled interarrival time

            
    # seed: the random seed with which the simulator is initiated
    # duration: the amount of simulation time for which the simulator has to run
    def simulate(self, seed, duration):
        random.seed(seed)
        env = simpy.Environment()

        bed = simpy.Resource(env, capacity = 12)
        receptionist = simpy.Resource(env, capacity = 1)
        nurse = simpy.Resource(env, capacity = 2)
        lab_assistant = simpy.Resource(env, capacity = 1)
        env.process(self.patient_generator(env, bed, receptionist, nurse, lab_assistant)) # start patient generation process
        env.run(duration)

        return env

diags = DiagnosticsSimulator()
env = diags.simulate(2019, 10000)
print(diags.nr_patients_processed, diags.sojourn_time_per_patient)
Reply
#2
show the complete unmodified error traceback.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: __init__() missing 1 required positional argument: 'successor siki 1 4,248 Mar-08-2021, 02:05 PM
Last Post: Larz60+
  Missing 1 required positional argument in python code edwinostby 7 9,743 Jan-19-2021, 12:52 PM
Last Post: Serafim
  Missing positional arguments error?? hhydration 2 2,099 Oct-01-2020, 05:33 AM
Last Post: buran
  TypeError: Missing required positional arguments liaisa 7 28,464 Sep-25-2020, 08:16 PM
Last Post: deanhystad
  missing 1 required positional argument jedmond2 4 6,570 Sep-19-2019, 12:00 PM
Last Post: jefsummers
  missing 1 required positional argument mcgrim 10 19,617 May-07-2019, 09:02 PM
Last Post: Yoriz
  TypeError: __init__() missing 3 required positional arguments Pythonhelp82 6 22,911 Jan-24-2019, 04:25 AM
Last Post: Pythonhelp82
  TypeError: method missing 1 positional argument koolinka 4 4,966 Nov-18-2018, 04:53 PM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,146 Nov-16-2018, 07:18 PM
Last Post: itmustbebunnies
  Class positional argument error itmustbebunnies 2 2,960 Nov-07-2018, 11:09 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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