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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:25:38+00:00 2026-06-14T13:25:38+00:00

In a Python software I am working on, I have a number of objects

  • 0

In a Python software I am working on, I have a number of objects that need to be able to be ‘connected’ to other objects (the term connected here referring to the fact that it just needs to point to the object it is connected to).

I have thought to create an connection class, which can create this link and store information about the properties of the connection. As shown below, when I create a new object, I have a method that allows me to add a new connection with a certain type to it.

class ConnectableObject()
    def addNewConnection(self, connectiontype)
        self.connections.append(NewConnection(connectiontype))

The idea is that each object should have their own connection type… and that these are connectable. i.e Object A has a connection object associated with it, Object B has a connection object associated with it, and to connection the two objects I just connect their connections. That allows me to store information about each connection in the connection objects. Once this connection object is instantiated I’d like to store in the connection object ‘who’ created it, i.e object A… object B. Is there a way in Python to request from an Object what class it was created within?

Also, more generally, is there a cleaner way to implement connections between objects where each object connection can store its own properties?

  • 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-14T13:25:39+00:00Added an answer on June 14, 2026 at 1:25 pm

    Is there a way in Python to request from an Object what class it
    created within?

    There are too many ‘connections’ in your question, so I’m not sure if my understanding correct, but I think you need to pass ConnectableObjectInstance.__class__ as an argument of the NewConnection constructor and then store it as a property of your connection object.

    EDIT:

    You don’t need to know a name of the object instance as it can be referenced via self. Also you probably don’t need to store class as a connection property, but a reference to an object. Something like that:

    >>> class Connection(object):
    ...  def __init__(self, parent):
    ...   self.parent = parent
    ...
    >>> class ConnectableObject(object):
    ...  def __init__(self):
    ...   pass
    ...  def connect(self):
    ...   return Connection(self)
    ...
    >>> conobj = ConnectableObject()
    >>> con = conobj.connect()
    >>> con.parent
    <__main__.ConnectableObject object at 0x01FDEC70>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python beginner here. I have a text file that is sorted into columns: fields
What is the biggest software development team that uses Python? I am wondering how
When I start any application, that I wrote with python for my Nokia 5800(software
python 2.7 how do you take any number and be able to compress it
Python beginner here, I have a list of lists and want to refer to
I have a working Python 2.6 install and just installed the PyQt4 built for
I was working on a program,that I need to support new additions. Hmmm. Let
I have a usb midi controller (uc-33e) and I have a working python script
i want that upon opening my N73's camera cover,the camera software keeps working as
Genesys is a contact center platform that provides software for working with both hard

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.