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 1019961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:05:41+00:00 2026-05-16T11:05:41+00:00

This post is the follow-up of my previous post (Create and retrieve object list

  • 0

This post is the follow-up of my previous post (Create and retrieve object list in Python).

I had to modify my code in the following way :

script1

#!/usr/bin/python

class Porsche:
    """ class representing a Porsche """
    def __init__(self, color):      
        self.color = color


def create_porsche(parameter_1, parameter_2):
    myPorsche = Porsche(color = parameter_1)
    myPorsche2 = Porsche(color = parameter_2) 

create_porsche(parameter_1 = 'blue', parameter_2 = 'red')
porsche_container = (myPorsche, myPorsche2)

and I’d like to have porsche_container = (myPorsche, myPorsche2) working the same way as in my previous script :

old script 1

#!/usr/bin/python

class Porsche:
    """ class representing a Porsche """
    def __init__(self, color):      
        self.color = color


myPorsche = Porsche(color = 'blue')
myPorsche2 = Porsche(color = 'red') 


porsche_container = (myPorsche, myPorsche2)

How can I do that please ?

rgds,

  • 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-05-16T11:05:42+00:00Added an answer on May 16, 2026 at 11:05 am

    Here is my take on how to go about creating Porsche objects and add them to a container.

    class Porsche(object):
        def __init__(self, color):
            self.color = color
    
    class PorscheCreator(object):
        def __init__(self):
            self._cars = []
        def create(self, *args, **kwargs):
            porsche = Porsche(*args, **kwargs)
            self._cars.append(porsche)
            return porsche
        def _get_cars(self):
            for each in self._cars:
                yield each
        cars = property(_get_cars)
    
    creator = PorscheCreator()
    myPorsche = creator.create('blue')
    myPorsche2 = creator.create('red')     
    

    And in script 2:

    from script1 import creator
    
    for each in creator.cars:
         print car.color
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up question to my previous post: Python/Scipy Interpolation (map_coordinates) Let's say
This post if a follow-up question to mt previous post: Android RESTful Web application
This is a follow-up question related to my previous post . Below is a
This is a follow up to a previous question that I had before about
This is a follow up question to a previous post on saving recent searches
This is a follow-on from a previous question I had: How to decouple my
I have an issue I have this jQuery code: $(document).ready(function(){ $(#follow).click(function(){ $.ajax({ type: 'POST',
This is a follow-up question of my previous post . I am trying to
I had the following error at previous question: Fluent NHibernate? Am I doing this
This is a follow up to my previous question about using XMLHttpRequest() to post

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.