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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:36:06+00:00 2026-06-05T23:36:06+00:00

I created many instances of a PlotHandler class. An instance must keep it’s variables

  • 0

I created many instances of a PlotHandler class. An instance must keep it’s variables private. But the way I managed them led to a hard to detect problem, a private list variable is shared between instances! And that too without any obvious source for the leak.

My debugging told me that the private member function that modifies the list sees the same list, even if they are different objects.

Is this a “gotcha” problem? What is the best way to troubleshoot this?


Here are the relevant parts (I hope they are!) of the implementation. Please see the ALL-CAPS comments:

The file implementing PlotHandler:

class PlotHandler(wx.Frame):
    __crop_section = None
    __projection   = None
    __crop_xcord   = None

    _band_data     = [] #THIS GETS SHARED

def _on_plot_click(self, xcord): #CALLED BY ANOTHER OBJECT
    band = self._analyze_band( xcord )
    self._band_data.append(band)
    ...

The parent class that it is managing PlotHandlers:

class MainFrame(wx.Frame):
    __close_callback__ = None
    _plot_handlers     = []
    def __init__(self, parent, title):
        ...


    def InitUI(self):
        ...

        img_handler = ImageHandler(panel)
        self.img_src.register_callback( img_handler.update_image )

        #you need to call PlotHandler(parent, cropped)
        img_handler.register_sample_callback( self._create_new_plot_handler )

        ...

    def _create_new_plot_handler(self, cropped_sample ):
    self._plot_handlers.append( PlotHandler(self, cropped_sample) ) #CREATE THEM
  • 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-05T23:36:09+00:00Added an answer on June 5, 2026 at 11:36 pm

    See this question, this one, and tons of other stuff you can find by googling “Python class variables shared”, “Python FAQ class variables”, etc.

    The short answer is: variables defined directly in the class body are class variables, not instance variables, and are thus shared among instances of the class. If you want instance variables you must assign them from within a method, where you have access to self.

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

Sidebar

Related Questions

I have a class that I can have many instances of. Inside it creates
Suppose 10 clients requests for a Servlet. How many servlet instances are created? Also
I am trying to come up with a way of taking a created instance
I'd like to know how many instances of a certain EJB bean are created.
I'm new to OOP. I created this class called Site that is extended but
My class represents a sequence of items. There can be many instances of such
I have a class named dot and many instances of this same class are
I have created many TestProjects with Visual-Studio-2010 Ultimate . All tests were executed successfully
Im using c# .net windows application form. I have created many databases with many
I am doing some testing for a very large website, created many different developers.

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.