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

  • Home
  • SEARCH
  • 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 8400637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:36:28+00:00 2026-06-09T21:36:28+00:00

In my function, I am creating unique variables that I want to add to

  • 0

In my function, I am creating unique variables that I want to add to a list. But whenever I append the next variable, the values of all the other variables inside the list change to the new one.

Here’s my code:

def make_list_of_data_transfer_objects(iFile, eFile, index_of_sheet):

    iBook = open_workbook(iFile)
    iSheet = iBook.sheet_by_index(0)

    eBook = open_workbook(eFile)
    eSheet = eBook.sheet_by_index(index_of_sheet)

    DataSet = namedtuple('DataSet', 'line_num data_list')

    list_objects = []
    temp_line_num = 99999
    temp_data = [0]*5

    for row_index in range(eSheet.nrows):
        temp_data[0] = eSheet.cell(row_index,0).value
        temp_data[1] = eSheet.cell(row_index,1).value
        temp_data[2] = eSheet.cell(row_index,2).value
        temp_data[3] = eSheet.cell(row_index,3).value
        temp_data[4] = eSheet.cell(row_index,4).value
        for row_index2 in range(iSheet.nrows):
            if temp_data[0] == iSheet.cell(row_index2,0).value:
                temp_line_num = row_index2
                temp_object = DataSet(temp_line_num, temp_data)

                list_objects.append(temp_object)

    #print list_objects #every object is the same

    list_objects.sort(key = lambda tup: tup[0]) #sort by line number

    return list_objects
  • 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-09T21:36:30+00:00Added an answer on June 9, 2026 at 9:36 pm

    Change

    temp_object = DataSet(temp_line_num, temp_data)
    

    to

    temp_object = DataSet(temp_line_num, temp_data[:])
    

    or

    temp_object = DataSet(temp_line_num, list(temp_data))
    

    By passing temp_data to the DataSet you do not create a copy of the list, you just re-use the existing one. By using [:] or list() you create a copy instead.

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

Sidebar

Related Questions

Hi all I want to sort 2 related files, creating an unique index which
I'm reading some tutorials now about jQuery.. function creating,plugin creation etc. but these tutorials
I am creating a function that I would like to generate random strings from
I'm looking for some Javascript jedi-master to assist in creating a function that adds
Let's say you have a object that is unique, and it's used by all
I have a function creating entries via grid() like this: (replace while-loop with function,
//dom <div id='toBeCloned'><span>Some name</span></div> <div id='targetElm'></div> //js $(function () { //creating a clone var
I am using CreateProcess function for creating the process, is there any option to
I am calling this from a function by creating an object.The progress box appears
Is it possible to define some sort of capitalize() or toLowerCase() function when creating

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.