I need a good approach to declare a lot of variables over a context. For exmaple in kubeflow, I need declare a pipeline with a lot components in order to do that, I use the following code:

component_1_op = comp.load_component(
component_n_op = comp.load_component(

Because of our line length rules I need to use two lines to do that. Another option is the following:

components = [
    ["component_op", 'path/to/component/1'],
    ["component_n_op", 'path/to/component/n']

components = {component: comp.load_component(path) for component, path in components}

1 Answer 1


Your second option is a good one. you are defining all your components up front, this is potentially reusable across pipelines, or makes testing easier as you can redefine what components to load to testing friendly ones. This is generally a good practice when you have a lot of values or key/values. This lets you clearly separate the intent of the code (loading needed components) from the details (where each component lives).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.