omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Class list

    Pythonista
    namespaces class list
    4
    7
    1801
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • resserone13
      resserone13 last edited by ccc

      When I print the master patient list it says name error. Why is it that I have trouble creating list inside of classes?

      
      
      
      class Patient (object):
      	
      		master_patient_list = []
      		current_patient_list = []
      		
      		def __init__(self, name=None, age=None, room_number=None, assigned_doctor=None, assigned_nurse=None, illness=None, iso_status=None, patient_record_nunber=None):
      				self.name = name
      				self.age = age 
      				self.room_number = room_number
      				self.assigned_doctor = assigned_doctor
      				self.assigned_nurse = assigned_nurse
      				self.illness = illness
      				self.iso_status = iso_status
      				self.patient_reord_number = patient_record_nunber
      				self.patient_medications = []
      				master_patient_list.append(self.name)
      		def add_patient():
      				pass
      				
      		def remove_patient():
      				pass		
      						
      		def __str__(self):
      				return f'Room: {self.room_number} \nName: {self.name} \nPhysician: {self.assigned_doctor} \nNurse: {self.assigned_nurse} \nIllness: {self.illness} \nIso status: {self.iso_status} \nPRN: {self.patient_reord_number}'	
      				
      
      #patient info				
      patient1 = Patient()
      patient1.name = 'Sally'
      patient1.age = 35
      patient1.room_number = 430
      patient1.assigned_doctor = 'Dr. Seuss'
      patient1.assigned_nurse = 'Jessica'
      patient1.illness = 'Broken Leg'
      patient1.iso_status = 'NONE'
      patient1.patient_reord_number = 'AD123456789'
      
      print(patient1)
      
      print(master_patient_list)
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @resserone13 last edited by

        @resserone13 Try

        master_patient_list = []
        current_patient_list = []
                
        class Patient (object):
        
        resserone13 1 Reply Last reply Reply Quote 0
        • resserone13
          resserone13 @cvp last edited by

          @cvp I’ve done that ad I works. With all my classes for patients,rooms, nurses, etc. it looks like I be having a lot of list being created at the beginning of my program. Is that usual?

          cvp mikael 2 Replies Last reply Reply Quote 0
          • cvp
            cvp @resserone13 last edited by

            @resserone13 No general answer. It depends on how you will manage these infos,
            A file yes/non? A dB/txt/json file?

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • mikael
                mikael @resserone13 last edited by

                @resserone13, in your original code the lists were class attributes, i.e. shared by all patient instances, and you could used them with self.master_list in the methods.

                Moving them outside the class made them globals, accessible everywhere.

                If you had created them inside the init they would have been instance attributes, specific to each patient, which of course makes no sense here.

                A usual pattern is to create an object that is responsible for a lists and knows all the operations that can be done with the list, like the CleaningLog in the other thread.

                resserone13 1 Reply Last reply Reply Quote 0
                • resserone13
                  resserone13 @mikael last edited by

                  @mikael for the way I’m using them I would like there to be one list of patients. Not a list associated with each patient. I guess that means I should create the list outside of the class. Making them global. I will check back on the other thread with the cleaning log and see what I can figure out. Thank you for the information.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors