Python Forum
Is there a library for recursive object creation using config objects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a library for recursive object creation using config objects
would like to be able to create objects of classes which inherit from something like Configurable through a factory method in addition to the normal constructor, where the factory method takes some kind of config object which is limited to JSON-serializable data types.

So in addition to
Class1(a=1, b="x")
it should be possible to also do
Class1.from_config(dict(a=1, b="x"))
This should work recursively so if the value of some initialization parameter is a configurable object it should get created from a nested config object through the from_config method, i.e. in addition to
 o1 = Class1(c=Class2())
it should be possible to do
 o1 = Class.from_config(dict(c=dict())
Each configurable object should have a method to return the config object that can be used to create a clone, e.g.
o1.get_config() == dict(c=dict())
My feeling is that this is such a basic approach that there should be many libraries already, but I could not really find one – could you point me to the right places?

The reason why I would like to find (or implement) this is because I would like to use this to duplicate my classes in other processes that way: send the config obejct of possibly nested complex classes to the other process to create a “twin” object to use there. One deeper reason for this is because that mechanism could then get extended to automatically handle the sharing of large datastructures when creating and using the config object to recreate twin objects in other processes.

Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic object creation using python gary 7 879 Oct-15-2022, 01:35 PM
Last Post: Larz60+
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,205 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  Updating a config file [solved] ebolisa 8 2,283 Nov-04-2021, 10:20 AM
Last Post: Gribouillis
  help with pytesseract.image_to_string(savedImage, config='--psm 11')iamge to string korenron 0 2,474 Apr-29-2021, 10:08 AM
Last Post: korenron
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 6,466 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Config file update Olivier74 0 1,330 Aug-18-2020, 03:36 PM
Last Post: Olivier74
  What is the best way to set application-wide config values? ajorona 1 1,732 May-07-2020, 05:03 PM
Last Post: buran
  Config file entry as list versus string? taziuk 2 1,599 Apr-25-2020, 12:01 PM
Last Post: ndc85430
  Player object wont recognize collision with other objects. Jan_97 3 2,439 Dec-22-2019, 04:08 PM
Last Post: joe_momma
  An Object of Objects? cebb 4 2,605 Jul-28-2019, 03:29 PM
Last Post: cebb

Forum Jump:

User Panel Messages

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