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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:19:57+00:00 2026-05-31T09:19:57+00:00

def group_move(group, damper): # Make a copy to test values new = group #

  • 0
def group_move(group, damper):
    # Make a copy to test values
    new = group

    # See what the original group value is
    print("Test = " + str(group.ctris[0].p1.x))
    dr = some float
    dx = some float
    dy = some float
    # Make changes to new
    moveGroup(new, dr, dx, dy)
    # See if those changes produce allowed values
    if (off_board_check(new) == 1):
        damper += 2.0
        # Reset to original to try again
        print("Test Here = " + str(group.ctris[0].p1.x))
        group_move(group, damper)
    else:
        # If everything is on the board, then make the change
        group = new

If I run this, I will see that on the very first recursion, the Test print line produces a different value from the Test Here print line. Why? How is this code possibly affecting the values of group? I am trying to pass an unchanged group onto the next recursive level of group_move in the case that the test values failed, but it seems that group is somehow being affected before I even make any recursive calls. How is the above any different from this:

>>> x = 1
>>> y = x
>>> x = 7
>>> y = 77
>>> x
7
>>> y
77
  • 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-31T09:19:58+00:00Added an answer on May 31, 2026 at 9:19 am
    # Make a copy to test values
    new = group
    

    The comment is incorrect. That does not make a copy. All that does is make a variable named new point at the same object that group is pointing at.

    If you want to create an actual copy, you may want to look at copy.deepcopy().

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

Sidebar

Related Questions

in my group controller I have two methods: def new @group = Group.new respond_to
def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in
How to group a collection of maps by multiple keys? For example: (def m1
How can I group map values by 2 different criteria to get the outputs
import json import urllib import re import binascii def asciirepl(match): s = match.group() return
I have the following models: # Group for Key/Value pairs class Group(models.Model): name =
I'm trying to collect emails from a group of people using the following: def
I have following helper method: def orders_chart_series(orders, start_time) orders_by_day = orders.where(:created_at => start_time.to_date..Date.today). group(date(created_at)).
I have a group of test cases that all should have exactly the same
def foo (): x = re.compile('^abc') foo2(x) def foo2(x): How do I get x

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.