-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Factory function that given a data structure, it returns a new generative data structure
e.g.
from collections import deque
from generative.structures import convert
q = convert(deque)Under the hood it could be implemented as follows:
import builtins
from generative import adapt
vars().update({k: adapt.adapt(v) if callable(v) else v for k, v in vars(builtins).items() if not k.startswith("__")})Import all python modules:
import os
import importlib
import sys
# Get the path of Python's lib directory
lib_path = os.path.dirname(os.__file__)
# Get a list of all .py files in lib directory
module_files = [f for f in os.listdir(lib_path) if f.endswith('.py')]
# Remove the .py extension to get the module names
module_names = [f[:-3] for f in module_files]
# Import the modules
native_modules = []
for name in module_names:
try:
module = importlib.import_module(name)
native_modules.append(module)
except:
pass # If a module fails to import, just skip it
print(native_modules) # This prints the list of imported native modulesThen can modify all native functionality with generative.adapt(<place functionality here>), but would need to modify the comprehension so that it recursively applies @adapt to functions of objects or use metaclasses.generate().
Reactions are currently unavailable