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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:34:42+00:00 2026-06-19T04:34:42+00:00

I used the following stack class in Python to store objects of another class.

  • 0

I used the following stack class in Python to store objects of another class.

class Stack :
 def __init__(self) :
   self.items = []

 def push(self, item) :
   self.items.append(item)

 def pop(self) :
   return self.items.pop()

 def isEmpty(self) :
   return (self.items == []) 
scopeStack=Stack();
object1=AnotherClass();
object1.value=2;
scopeStack.push(object1);

On changing the contents of the object object1 outside the stack, the contents of the stack’s object changed too.

 object1.value=3;
 obj=scopeStack.pop();
 print obj.value; #gives output 3

What should I do to NOT have this dynamic binding between a local variable and the stack’s inner variables?

  • 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-19T04:34:43+00:00Added an answer on June 19, 2026 at 4:34 am

    Check out the copy module found here. What you are looking for is called copy.deepcopy().

    Example:

    class Obj:
        def __init__(self, value):
            self.value = value
    
    x = Obj(5)
    y = copy.deepcopy(x)
    
    print 'x:', x.value
    print 'y:', y.value
    
    x.value = 3
    
    print 'x:', x.value
    print 'y:', y.value
    

    Output:

    x: 5
    y: 5
    x: 3
    y: 5    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: class MyCustomDescriptor: def __init__(self,foo): self._foo = foo def __call__(self,decorated_method): #
I am using TimeStamp class to convert seconds into Day,Hours,Minutes,Seconds. I used following code
Exceptional C++ mentions the following code template <class T> class Stack { public: Stack();
I used following code, but it displays only 2 digit of ISO country name.
I used following JS code to create equal height columns: var colHeight = Math.max($('.3columngallery
I have used following code to convert string to json and parse it. String
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I am trying to used following code but I am not getting good performance
I've used following code snippet for my activity in order to deal with orientation

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.