I want to have some simple interfaces for the users to connect some pre-defined modules (I'm free to modify them if I have to). Each module has a few named inputs and outputs. One module may connect to a few modules. A few modules can connect to a single module.
This is what I have in my mind so far: Option 1: Each module has "in" and "out" dictionary for input and output, and the connection is made through code like this:
a.out["out 1"].to(b.in["in 1"]) # connect a's "out 1" output to b's "in 1" input
a.out["out 2"].to(b.in["in 2"]) # connect a's "out 2" output to b's "in 2" input
But this looks quite tedious, so I came up with Option 2:
# connect a to b, also a to c, then list which inputs connect to which outputs
a.to(b,{"out 1":"in 1",
"out 2":"in 2"},
c,{"out 4":"in 1",
"out 3":"in 2"})
This seems to look better as it's clearer to me which modules are connected and also the mapping between their outputs and inputs.
I wonder if there is any room to improve the above, to clearly show:
- module level connections, e.g. module a connect to module b
- outputs and inputs connections
- simple and clear interface. By 'simple', I mean less typing; 'clear' means easy to understand. I understand that sometimes I can't have both in that case, 'clear' interface is preferable.
I'm not proficient in Python(2.7) so there might be some syntax or operator or data structure that I am not aware of but I may be able to take advantage for this purpose.
Aucun commentaire:
Enregistrer un commentaire