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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:26:50+00:00 2026-05-13T16:26:50+00:00

I am trying to add an object to a list but since I’m adding

  • 0

I am trying to add an object to a list but since I’m adding the actual object when I try to reset the list thereafter, all the values in the list are reset.
Is there an actual way how I can add a monitor object to the list and change the values and not affect the ones I’ve already saved in the list?

Thanks

Code:

arrayList = []

for x in allValues:


        result = model(x)

        arrayList.append(wM)

        wM.reset()

where wM is a monitor class – which is being calculated / worked out in the model method

  • 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-13T16:26:51+00:00Added an answer on May 13, 2026 at 4:26 pm

    Is your problem similar to this:

    l = [[0]] * 4
    l[0][0] += 1
    print l # prints "[[1], [1], [1], [1]]"
    

    If so, you simply need to copy the objects when you store them:

    import copy
    l = [copy.copy(x) for x in [[0]] * 4]
    l[0][0] += 1
    print l # prints "[[1], [0], [0], [0]]"
    

    The objects in question should implement a __copy__ method to copy objects. See the documentation for copy. You may also be interested in copy.deepcopy, which is there as well.

    EDIT: Here’s the problem:

    arrayList = []
    for x in allValues:
        result = model(x)
        arrayList.append(wM) # appends the wM object to the list
        wM.reset()           # clears  the wM object
    

    You need to append a copy:

    import copy
    arrayList = []
    for x in allValues:
        result = model(x)
        arrayList.append(copy.copy(wM)) # appends a copy to the list
        wM.reset()                      # clears the wM object
    

    But I’m still confused as to where wM is coming from. Won’t you just be copying the same wM object over and over, except clearing it after the first time so all the rest will be empty? Or does model() modify the wM (which sounds like a terrible design flaw to me)? And why are you throwing away result?

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

Sidebar

Related Questions

I am trying to add an object to an arraylist but when I view
I am trying to add a draggable object to to a simple html page.
I'm trying to add support for stackoverflow feeds in my rss reader but SelectNodes
I'm trying to figure out how to add an enumeration to an object with
I'm trying add a tab to my web page that looks like this: Using
Trying to add an onclick handler to my tabs, and can't seem to get
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I was trying to add a favicon to a website earlier and looked for
I am trying to add a project reference or swc to papervision in FlashDevelop
I am trying to add some custom build steps to my headless build process

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.