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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:13:57+00:00 2026-05-28T15:13:57+00:00

I just spent a very long time debugging an issue in python, using the

  • 0

I just spent a very long time debugging an issue in python, using the web.py framework, and it has me wondering about a way to check this kind of thing in the future.

In short, one of the methods of web.py’s database class was returning a storage object that, I can only surmise, was a reference to a value in memory, instead of a copy. The result was that no matter what I tried to do, I could not append multiple results of a query into a list, because the list just wound up with copies of the same row of data.

To solve it, I had to create another dictionary and convert all values in the web.py storage object explicitly to another datatype (I just used strings to get it working) so that it would be forced to create a new object.

In code, this is what was happening:

>>> result = db.query(query_params)
>>> for row in result:
>>>     print row
...     result_list.append(row)
{"result" : "from", "row" : "one"}
{"result" : "from", "row" : "two"}
>>> print result_list
[{"result":"from", "row" : "two"}, {"result" : "from", "row" : "two}]

This is what clued me into the fact that this was some sort of reference issue. The list was storing the location of “row”, instead of a copy of it.

The first thing I tried was something along the lines of:

 copy = {}
 for row in result:
    for value in row:
        copy[value] = row[value]
    result_list.append(copy)

But this lead to the same problem.
I only found a solution by tweaking the above to read:

            copy[value] = str(row[value])

So, my question is two-fold, really:

  1. Is there an easy way to tell how something is being stored and/or passed around?
  2. Is there a way to explicitly request a copy instead of a reference?
  • 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-28T15:13:57+00:00Added an answer on May 28, 2026 at 3:13 pm

    Use copy. It allows simple shallow- and deep-copying of objects in python:

    import copy    
    result_list.append(copy.copy(row))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just spent way too long trying to diagnose why, in the following snippet
I have spent some time debugging a weird issue with ARC and custom dealloc
I've just spent a very frustrating afternoon trawling Google looking for a commercial-grade WPF
I spent a long time learning how to customise WCF from the point of
I just spent a fair amount of time selecting the files and directories I
I just spent most of a day tracking down a very strange case where
So I just spent around an hour trying to unveil and resolve a very
I'm trying to investigate a very long start up time for my app and
I have been using Python for about a year now, coming from a mostly
Having just spent ages debugging this, I'm keen to understand what exactly is going

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.