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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:40:46+00:00 2026-05-24T03:40:46+00:00

I find myself repeating a common pattern when trying to execute code across multiple

  • 0

I find myself repeating a common pattern when trying to execute code across multiple objects.

Arg_list_one = ["first","second", "so on"]
Arg_list_two = ["first","second", "so on"]


MANIFEST = [ ]

class connection(object):
    def __init__(self, args):
        ...
        MANIFEST.append(self)
    def Run(self):
        ...

connection(Arg_list_one)
connection(Arg_list_two)

[conn.Run() for conn in MANIFEST]

Is this a pattern (or anti-pattern)? Or just something that I made up?

Are there other, better, ways of doing this?

  • 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-24T03:40:47+00:00Added an answer on May 24, 2026 at 3:40 am

    Why would you need a list of all objects ever created? Many of those may belong to completely unrelated pieces of your application! A given piece of code shouldn’t assume it’s the only one to user a class. Especially since there’s usually no need to:

    • A function creates a bunch of objects and then does something to all of them? Put the objects into a temporary, locally-scoped list.
    • Need to share some objects between functions? Put them in a list, pass the list to whoever should see the objects.
    • Instances of some class share some of these object? Make a list of them and put them in the class.
    • Et cetera, you see where this is going.

    A more practical and less stylistic issue is that this list would keep every single object of that class that’s ever instanciated alive forever. And they say one can’t create memory leaks in Python… (This can be avoided with weak reference, but would make the code much more complex to transparently remove dead references.)

    The solution is barely more typing and saves you a whole lot of headaches later on. Next you’ll use local variables to save yourself a return?

    connections = [Connection(arg_list_one), Connection(arg_list_two)]
    for connection in connections:
        connection.run()
    

    That said, there may be situations where such a list may be useful (with a fix for said memory leak, of course). I just don’t see anything close to that in your example, and I think such situations are very rare.

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

Sidebar

Related Questions

When setting up an instance of the excellent TortoiseSVN , I find myself repeating
I find myself using the 'pattern' below rather unsettlingly often, when I want to
long time reader, first time question-er. I've found myself in a unique situation, and
I am experienced at creating advanced CSS sprites by hand, but I now find
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I'm doing some changes on my routes, and suddenly the following is appearing in
I have a new web app that is packaged as a WAR as part
I'm working in Django. In Django, when you're rendering a template you send it
Does anyone know of a site, newsgroup, message board, etc. where I can submit
I have an ASP.NET website that I built that has grown considerably in size

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.