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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:04:32+00:00 2026-05-26T11:04:32+00:00

As an example, just a couple of dummy objects that will be used together.

  • 0

As an example, just a couple of dummy objects that will be used together. FWIW this is using Python 2.7.2.

class Student(object):
    def __init__(self, tool):
        self.tool = tool

    def draw(self):
        if self.tool.broken != True:
            print "I used my tool. Sweet."
        else:
            print "My tool is broken. Wah."

class Tool(object):
    def __init__(self, name):
        self.name = name
        self.broken = False

    def break(self):
        print "The %s busted." % self.name
        self.broken = True

Hammer = Tool(hammer)
Billy = Student(Hammer)
Tommy = Student(Hammer)

That’s probably enough code, you see where I’m going with this. If I call Hammer.break(), I’m calling it on the same instance of the object; if Billy’s hammer is broken, so is Tommy’s (it’s really the same Hammer after all).

Now obviously if the program were limited to just Billy and Tommy as instances of Students, the fix would be obvious – instantiate more Hammers. But clearly I’m asking because it isn’t that simple, heh. I would like to know if it’s possible to create objects which show up as unique instances of themselves for every time they’re called into being.

EDIT: The kind of answers I’m getting lead me to believe that I have a gaping hole in my understanding of instantiation. If I have something like this:

class Foo(object):
    pass

class Moo(Foo):
    pass

class Guy(object):
    def __init__(self, thing):
        self.thing = thing

Bill = Guy(Moo())
Steve = Guy(Moo())

Each time I use Moo(), is that a separate instance, or do they both reference the same object? If they’re separate, then my whole question can be withdrawn, because it’ll ahve to make way for my mind getting blown.

  • 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-26T11:04:32+00:00Added an answer on May 26, 2026 at 11:04 am

    After seeing the tenor of the answers here and remembering the Zen of Python, I’m going to answer my own dang question by saying, “I probably should have just thought harder about it.”

    I will restate my own question as the answer. Suppose I have this tiny program:

    class Item(object):
        def __init__(self):
            self.broken = False
    
        def smash(self):
            print "This object broke."
            self.broken = True
    
    class Person(object):
        def __init__(self, holding):
            self.holding = holding
    
        def using(self):
            if self.holding.broken != True:
                print "Pass."
            else:
                print "Fail."
    
    Foo = Person(Item())
    Bar = Person(Item())
    
    Foo.holding.smash()
    Foo.using()
    Bar.using()
    

    The program will return “Fail” for Foo.using() and “Pass” for Bar.using(). Upon actually thinking about what I’m doing, “Foo.holding = Item()” and “Bar.holding = Item()” are clearly different instances. I even ran this dumpy program to prove it worked as I surmised it did, and no surprises to you pros, it does. So I withdraw my question on the basis that I wasn’t actually using my brain when I asked it. The funny thing is, with the program I’ve been working on, I was already doing it this way but assuming it was the wrong way to do it. So thanks for humoring me.

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

Sidebar

Related Questions

This is just an example, but given the following model: class Foo(models.model): bar =
Usually I was doing something like that (just a example): using (Stream xmlStream =
Just using this as an example... Here are the columns in my UserProfile table:
I just started using Qt and noticed that in each example code folder there
Say I have something like -- this is just an example mind you. class
I'm using logos as just an example. I'm trying to use themes/skins for the
The example below, is just an example, I know that I don't need an
I have a custom c# type like (just an example): public class MyVector {
I just tossed this super simple code example into a Flash CS4 IDE frame
I have a couple questions. This is an example of what i'm trying to

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.