Hey guys, I'm trying to do a "for loop" on the cat...
# questions
z
Hey guys, I'm trying to do a "for loop" on the catalog, so I am using TemplatedConfig so I can use jinja. I am trying with the following way, and I am not sure why it is not working. Catalog:
Copy code
{%- for item in mylist %}
out.blind_predictions_{{ item-}}:
    type: pandas.CSVDataSet
    filepath: ${filepath1}_{{ item-}}.csv
    layer: out
{% endfor %}
Globals:
Copy code
mystli:
    - item1
    - item2
(For obvious reasons I removed the actual names from the text here) Does anyone know how to accomplish this? (do a for here)
n
https://docs.kedro.org/en/stable/configuration/advanced_configuration.html#how-to-use-jinja2-syntax-in-configuration You may need to create your custom config loader,
mylist
can be interpolated with
${my_list}
but it cannot be used to form the for-loop.
Cc @Ankita Katiyar as I think this is a good example to include for the migration guide
👍 1
z
Wow, I had no idea about this dataset factory. I will try it out.
n
It's relatively new feature, we are still trying to improve the docs so we haven't promoted this feature yet.
z
I am using kedro 0.18.3, but I don't seem to have config.OmegaConfigLoader, do I need to upgrade my kedro?
Also, do you know why I cannot use the for loop? If it supports jinja, I don't see why I can't.
n
You will need to upgrade your kedro version.
For loop is supported, if you change
Copy code
{%- for item in mylist %}
to
Copy code
{%- for item in ["item1", "item2"] %}
it should work.
Under the hood the config was loaded with
anyconfig
, to pass global variable into Jinja is not supported out of the box.
z
So the for works, but I cannot use variables? Hmm, that's weird haha
The for will do it for my case, thank you for the tips!
👍🏼 1