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
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 4,805 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  Applications config files / Best practices aecordoba 2 4,836 Oct-23-2024, 12:56 PM
Last Post: aecordoba
  dynamic object creation using python gary 7 3,454 Oct-15-2022, 01:35 PM
Last Post: Larz60+
  Updating a config file [solved] ebolisa 8 5,056 Nov-04-2021, 10:20 AM
Last Post: Gribouillis
  help with pytesseract.image_to_string(savedImage, config='--psm 11')iamge to string korenron 0 4,631 Apr-29-2021, 10:08 AM
Last Post: korenron
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 12,420 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Config file update Olivier74 0 2,290 Aug-18-2020, 03:36 PM
Last Post: Olivier74
  What is the best way to set application-wide config values? ajorona 1 3,137 May-07-2020, 05:03 PM
Last Post: buran
  Config file entry as list versus string? taziuk 2 3,158 Apr-25-2020, 12:01 PM
Last Post: ndc85430
  Player object wont recognize collision with other objects. Jan_97 3 4,520 Dec-22-2019, 04:08 PM
Last Post: joe_momma

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.