Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:50:41+00:00 2026-06-18T08:50:41+00:00

I have a library of component objects. I would like to include instantiations of

  • 0

I have a library of component objects. I would like to include instantiations of a selection of those objects in another object. But I would like to provide that selection as a list so that each time I instantiate the container object with a list, it will be created with the specified sub objects in it.

Let’s say my component library looks like this:

class ColorBlob(object):
    ...
    def wipeItUp()
        ...

class RedBlob(ColorBlob):
    ...
    def paintIt()
        ...
class YellowBlob(ColorBlob):
    ...
    def paintIt()
        ...
class BlueBlob(ColorBlob):
    ...
    def paintIt()
        ...

And my container object looks like this:

class Pallet(object):
    def __init__(self, colorList):
        for color in colorList:
            #Ok, here is where I get lost if I know the color I can do this:
            Pallet.BlueBlob = blobLib.BlueBlob()
            #But I don't, so I am trying to do something like this:
            blobSpecs       = getattr(blobLib, color)
            blobSpecs.Obj   = blobSpecs().returnObj(self.page) # with "returnObj" defined in the library as some other method
            setattr(self, Pallet.blobName, blobSpecs) #and I am completely lost.

But what I really want to do in my functional code is this:

workingPallet=Pallet(['RedBlob', 'BlueBlob'])
workingPallet.RedBlob.paintIt()

I know that I am lost when I try to instantiate the sub objects in the container. Can someone help me straighten out my “getattr” and “setattr” nonsense?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:50:42+00:00Added an answer on June 18, 2026 at 8:50 am

    You were almost there, but it isn’t your getattr or setattr that’s the problem. You end up setting the class back on self, not the instance you created:

    def __init__(self, colorList):
        for color in colorList:
            blobSpec       = getattr(blobLib, color)
            blob           = blobSpec()    # create an instance of the blob
            blob.Obj       = blob.returnObj(self.page) 
            setattr(self, color, blob)
    

    It’s the same thing as calling the class directly (BlueBlob()), but now through a variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library written in C that I would like to use in
i have written a library with some classes that make use of qt object
I have a native/unmanaged C++ library with a number of classes that I would
I have created a Class Library (Core Processing Component) using C# in Visual Studio
I have a library made in C++/GDI that I am trying to port to
I have a library project that should be the base for several web applications.
I have a library that interacts with our phone system, ie, Hey phone, call
We have a Library Project that we use for all our central reused code
I've got an architecture like the following: Data (Class Library that handles our Entity
I have a simple class library that I use in Excel. Here is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.