from partcompound import Compound # Define a basic compound with two components compound = Compound() component1 = "Component 1" component2 = "Component 2" compound.add_component("c1", component1) compound.add_component("c2", component2) # Get the components individually print(compound.components.c1) # Output: Component 1 print(compound.components.c2) # Output: Component 2 # Get the components as a dictionary print(compound.get_components()) # Output: {'c1': 'Component 1', 'c2': 'Component 2'}
from partcompound import Compound # Define a hierarchical compound with nested components compound = Compound() component1 = "Component 1" subcompound = Compound() subcompound.add_component("sub1", "Subcomponent 1") subcompound.add_component("sub2", "Subcomponent 2") component2 = subcompound compound.add_component("c1", component1) compound.add_component("c2", component2) # Get the components recursively print(compound.get_components()) # Output: # {'c1': 'Component 1', # 'c2': {'sub1': 'Subcomponent 1', 'sub2': 'Subcomponent 2'}}In both examples, the package library used is `partcompound`.