Python Forum
Possible to create an object inside another object that is visible outside that objec
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible to create an object inside another object that is visible outside that objec
#5
Your examples are more baffling than illustrative. Is somemethod() supposed to be a method of Aclass? In your example it is a function, not a method of Aclass. An example should be valid Python code.
class Bclass:
    pass

class Aclass:
    def somemethod(self):
         self.B = Bclass

obj_a = Aclass()
obj_a.B   # Will raise an AttributeError because B does not exist yet.
obj_a.somemethod()  # This creates B
obj_a,B  # Returns Bclass.
The answer is that an object attribute is an object attribute. The type of the attribute does not matter.
Reply


Messages In This Thread
RE: Possible to create an object inside another object that is visible outside that objec - by deanhystad - May-24-2023, 02:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,418 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  type object 'man' has no attribute 'centerX' Tempo 7 851 Mar-07-2025, 03:47 AM
Last Post: deanhystad
  float object can't be interpreted as an integer t23 2 913 Jan-18-2025, 07:36 PM
Last Post: deanhystad
  Storing DictProxy object and modifying its nested value? haihal 3 1,083 Dec-20-2024, 04:58 AM
Last Post: deanhystad
  Extract args=, value that was passed to Multiprocessing.Proc object during runtime? haihal 1 646 Dec-08-2024, 07:04 AM
Last Post: Gribouillis
  what is solution to save and reload a object? eue 4 2,076 Nov-23-2024, 02:15 PM
Last Post: DeaD_EyE
  Trying to get JSON object in python and process it further Creepy 2 1,029 Oct-24-2024, 08:46 AM
Last Post: buran
  How to move an object over time rather than instantly? temlotresid6 3 1,709 Oct-23-2024, 11:20 AM
Last Post: temlotresid6
  Forward __getattr__ to another object. deanhystad 1 770 Aug-30-2024, 07:16 AM
Last Post: Gribouillis
  How can I upload a .gz file to the Swift Object Storage using Python swift client? Hanginium65 0 758 Jul-24-2024, 03:24 PM
Last Post: Hanginium65

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020