[Answer]-Suggestion for correct python syntax

1👍

If you want to be able to support that syntax for building a Workflow from Nodes, then you should be able to do this using operator overloading. Here is an excellent quick reference on operators that can be overloaded in Python.

As suggested by @AshwiniChaudhary the pickle module could handle storing Python objects in files.

0👍

Not sure from your question, but If the point is to store an arbitrary configuration tree I’d advice you to stick with “normal” data types if possible. That way your configuration data will be far more easy to store and far more portable.

Regarding the semantics and order, you can always do something like this (a little bit Lisp-like thing):

conf = [
    ['Workflow',
        ['and',
            ['Node', 1, 2],
            ['or',
                ['Node', 4, 2],
                ['Node', 5, 6]
            ],
            ['Node', 1, 7]
        ]
    ]
]

If it’s too ugly for your humans, you can use YAML (not in core Python libs though; use PyYaml):

- - Workflow
  - - and
    - [Node, 1, 2]
    - - or
      - [Node, 4, 2]
      - [Node, 5, 6]
    - [Node, 1, 7]

(Note that I’m using lowercase for operators and first-uppercase for classes.)

Leave a comment