Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Subclasses
#2
I really don't understand why so complicated. It looks like you are really confused about inheritance and instantiation.

At the moment basically you cannot use your BaseClass. You can use only the Person1 class. From what you show you must combine BaseClass and Person1 class into single BaseClass and user can subclass that BaseClass

class BaseClass: # in python3 all classes are "new style" classes and inherit from object
    def __init__(self, name):
        self.name = name
    
    def print_name(self):
        print(self.name)
 
class CustomClass(BaseClass):
    def print_name(self):
        print("Hello my name is %s" % self.name)

foo = CustomClass('Bob')
foo.print_name()

bar = BaseClass('Joe')
bar.print_name()
Note, there is no need to generate new classes for every name from dataset (because it sounds that's what you are doing). That's what the instances are.
BaseClass may reside in different module from the one in which CustomClass is defined, user just need to import BaseClass
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
User Subclasses - by holyghost - Mar-16-2021, 08:10 PM
RE: User Subclasses - by buran - Mar-16-2021, 08:47 PM
RE: User Subclasses - by holyghost - Mar-16-2021, 11:40 PM
RE: User Subclasses - by deanhystad - Mar-17-2021, 03:36 AM
RE: User Subclasses - by buran - Mar-17-2021, 12:03 PM
RE: User Subclasses - by deanhystad - Mar-17-2021, 12:18 PM
RE: User Subclasses - by buran - Mar-17-2021, 12:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "unexpected keyword arg" when initializing my subclasses Phaze90 3 3,222 Nov-25-2022, 07:39 PM
Last Post: Gribouillis
  which design / pattern when building classes and subclasses Phaze90 2 1,143 Nov-19-2022, 08:42 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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