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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:03:29+00:00 2026-05-26T19:03:29+00:00

I have created an object type.. and after initilializing I am pushing that into

  • 0

I have created an object type.. and after initilializing I am pushing that into a list.
but for some reason the behavior is not as expected.
let me put in the sample code.. and then the output.

def allignDatesToWhenWasItemSold(pilotInstance):
    unitsSoldPerDay = pilotInstance._units_sold_per_day
    productPart = pilotInstance._product
    date = productPart._date
    quantity = pilotInstance._product._quantity

    listOfPilotInstance = []
    for i in range(len(unitsSoldPerDay)):
        perDayQuantity = unitsSoldPerDay[i]
        #modDate = date
        #print perDayQuantity
        modDate = modifyDate(date, i)
        productPart._date = modDate

        #print "pro ", productPart._date
        newPilotInstance = PilotTest(productPart, pilotInstance._name,perDayQuantity)
        print "here ",newPilotInstance._product._date._date, ' ',newPilotInstance._product._date._month, ' ', newPilotInstance._units_sold_per_day
        #newPilotInstance.setDate(modDate)

        listOfPilotInstance.append(newPilotInstance) #note this line.. this is where the trouble is
        for k in listOfPilotInstance:
            print k._product._date._date

    for ele in listOfPilotInstance:
        print "there " ,ele._product._date._date, ' ',ele._product._date._month, ' ',ele._units_sold_per_day
    return listOfPilotInstance

The out put are as following

here  30   7   1
30
here  31   7   0
31<--- now this shouldnt be like this.. as I am doing append.. teh first ele shoulnt be overwrited??
31
here  1   8   2
1
1
1
there  1   8   1
there  1   8   0
there  1   8   2

So my query is that since I am doing the append.. why is the date element getting overwrited?
Any clue as in what I am doing wrong?
Thanks

  • 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-26T19:03:29+00:00Added an answer on May 26, 2026 at 7:03 pm

    You are using the same productpart instance, and just mutating it:

    productPart._date = modDate
    

    Since all the PilotTest objects have a reference to the same productPart instance, all of them see the mutation.

    You need to create a new instance of your class on each iteration through the loop and assign this new instance to productPart.

    productPart = ...something here...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created an IE band object (toolbar) that is working well. however, when
I have created some python code which creates an object in a loop, and
I have an ExpenseType object that I have created with the following migration: class
I have a stdClass object created from json_decode that won't return the right number
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
Let me first describe my goal: I have created an object with 3 properties:
I have created a json object from ruby with cobravsmongoose, however the attributes have
I have an object created in a host application and can access it remotely
I have created a file with printStream object as shown below. PrintStream outPutOffice =
I have tree control object created using CTreeCtrl MFC class. The tree control needs

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.