Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Managing Objects
#1
Hello all

I was wondering if anyone could help shed some light on how to manage objects once they have been instantiated.

I have a class that creates a person that takes various attributes and uses 2 x methods, the code is as follows:-

from datetime import date

class Human():

    
    def __init__(self, name, sex, eyecolor, height, yearborn):
        self.name = name
        self.sex = sex
        self.eyecolor = eyecolor
        self.height = height
        self.yearborn = yearborn
        
        print("Object", self.name, self.sex, self.eyecolor, self.height, self.yearborn, "Has been created")
        
    
    def age(self):
        currentdate = date.today()
        a = currentdate.year - self.yearborn
        return a
    
    def display(self):
        print(self.name)
        print(self.sex)
        print(self.eyecolor)
        print(self.height)
        print(self.yearborn)
I create the object using the code:-

Tom = test.Human("Tom","Male", "Green",178,1989)
After the I have performed, for example, calculating the age then what do I with the object if I no longer need it - do I delete the object, can I safety forget about it - does it just sit in memory?

Also is there any way of determining how many objects have been created by a class?

Thank you.
Reply
#2
You don't need to worry about managing objects if an object is no longer referenced anywhere it will get garbage collected.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  managing new windows JonWayn 1 1,769 Sep-22-2022, 05:26 PM
Last Post: Larz60+
  Managing dependencies with pipenv t4keheart 6 2,922 Aug-05-2020, 12:39 AM
Last Post: t4keheart
  managing command codes for external controller box Oolongtea 0 1,908 Sep-19-2019, 08:32 AM
Last Post: Oolongtea
  Python what should be name of the module for managing data of users ? harun2525 3 3,406 Dec-06-2017, 06:11 PM
Last Post: nilamo
  managing modules/scripts dynamically hbknjr 2 3,074 Oct-06-2017, 05:07 PM
Last Post: hbknjr

Forum Jump:

User Panel Messages

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