سؤال

Is it possible to define a buildout variable of type dictionary?

I am trying to substitute a variable with a dictionary but buildout considers it a string.

E.g.

in buildout.cfg:

[MYPROG]
    progr_args = 
           a : 1 
           b : 2
           d : 
             d1: 1
             d2: 2

in template:

my_params:
    {% for key, val in parts.MYPROG.progr_args.items() %}\
        ${key}: ${val}\
    {% end %}
هل كانت مفيدة؟

المحلول

Not with Buildout itself, no. Buildout configuration values are always strings; even the mr.scripty recipe, which lets you use Python code as part of your buildout configuration, stores the results of the Python code a strings.

Ever worse, initial whitespace from continuation lines is stripped, so your entry:

progr_args = 
       a : 1 
       b : 2
       d : 
         d1: 1
         d2: 2

is stored as \na : 1\nb : 2\nd :\nd1: 1\nd2: 2, having lost all indentation context.

You'll have to use Genshi itself to parse out your values. I suggest you use a separate section:

[MYPROG]
prog_params = section_name

[section_name]
a = 1
b = 2

and in your template:

my_params:
{% for key, val in parts[parts.MYPROG.progr_args].items() %}\
    ${key}: ${val}\
{% end %}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top