<p>Hi;<br>Forgive multiple posts in one day: online very infrequently<br>I set the following variables:<br># Headers are kept in order to determine nesting of chapters<br># They are labeled according to font size<br>h36 = ''<br>
h26 = ''<br>h22 = ''<br>h18 = ''<br>h14 = ''<br>h12 = ''<br>header_sizes = [36, 26, 22, 18, 14, 12]<br># Size is the font size of the header<br>size = 0</p>
<p>I write code that grabs the size var.<br>Then I have the following very laborious spaghetti code:</p>
<p>if size == 36:<br>  h36 = line<br>  h26 = ''<br>  h22 = ''<br>  h18 = ''<br>  h14 = ''<br>  h12 = ''<br>elif size == 26:<br>  h26 = line<br>  h22 = ''<br>  h18 = ''<br>
  h14 = ''<br>  h12 = ''<br>elif size == 22:<br>  h22 = line<br>  h18 = ''<br>  h14 = ''<br>  h12 = ''<br>elif size == 18:<br>  h18 = line<br>  h14 = ''<br>  h12 = ''<br>
elif size == 14:<br>  h14 = line<br>  h12 = ''<br>elif size == 12:<br>  h12 = line<br>else:<br>  # THROW ERROR!</p>
<p>I would like something more elegant, like this:<br># del is used to determine if should reset the lower header values to ''<br>del = 0<br>for header_size in header_sizes:<br>  if header_size == size:<br>    # The following line is ILLEGAL<br>
    h + string(header_size) = line<br>    del = 1<br>  if del = 1<br>    # The following line is ILLEGAL<br>    h + string(header_size) = ''</p>
<p>How can I rewrite those illegal lines, such that I can create the proper name for the variable, and write the necessary data?<br>TIA,<br>Victor<br></p>
<p> </p>