<div class="gmail_quote">On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div>exec is a statement, and statements don't have "return values."   It's not a function, so there are no parentheses in its syntax, either.  exec is also a technique of last resort;  there's nearly always a better/safer/faster way to accomplish what you might want, but of course you don't say what that is.<br>
</div>
<br>
As for "returning" values, exec by default uses the same global space as your app, so you can just modify a global variable in your "called" code and use it afterwards.<br>
<br>
abc = 42<br>
value = 12<br>
exec "abc = %d" % value<br>
print abc<br></blockquote><div><br>Taking out the parenthesis did it! Thanks. Now, you state this is an option of last resort. Although this does indeed achieve my desired aim, here is a complete example of what I am trying to achieve. The following is from 'createTables2.py':<br>
<br>  for table in tables:<br>    try:<br>      exec 'from options import %s' % table<br>    except:<br>      pass<br>    try:<br>      exec '%s()' % table<br>    except:<br>      pass<br><br><br>The following is from 'options.py':<br>
<br>def jewelry(which=''):<br>  code = []<br>  names = []<br>  meanings = []<br>  code.append(['5', '5&frac12;', '6', '6&frac12;', '7', '7&frac12;', '8', '8&frac12;', '9', '9&frac12;', '10', '10&frac12;', '11', '11&frac12;', '12', '12&frac12;', '13', '13&frac12;'])<br>
  meanings.append('The standard ring sizes.')<br>  names.append('ringSizes')<br>  code.append(['Petite (7&#34;)', 'Average (7&frac12;&#34;)', 'Large (8&#34;)', 'Extra-large (8&frac12;&#34;)'])<br>
  meanings.append('The standard bracelet sizes.')<br>  names.append('braceletSizes')<br>  code.append(['16&#34;', '18&#34;', '20&#34;', '22&#34;', '24&#34;'])<br>
  meanings.append('The standard necklace sizes.')<br>  names.append('necklaceSizes')<br>  code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K white gold', 'platinum', 'tungsten', 'titanium'])<br>
  meanings.append('The standard jewelry metals.')<br>  names.append('metals')<br>  code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', 'turquoise'])<br>
  meanings.append('The standard jewelry stones.')<br>  names.append('stones')<br>  if which == '':<br>    i = 0<br>    all = ''<br>    while i < len(meanings):<br>      table = '%s\n' % meanings[i]<br>
      table += "<table>\n <tr>\n  <td colspan='8' align='center'>%s</td>\n </tr>" % names[i]<br>      j = 0<br>      for elt in code:<br>        if (j + 8) % 8 == 0:<br>
          table += ' <tr>\n'<br>        table += '  <td>%s</td>\n' % code[i]<br>        if (j + 8) % 8 == 0:<br>          table += ' </tr>\n'<br>        j += 1<br>      if table[-6:] != '</tr>\n':<br>
        table += ' </tr>\n'<br>      table += '</table>\n'<br>      all += table + '<br /><br />'<br>      i += 1<br>    print all<br><br>This all works fine; however, if there is a better way of doing it, please let me know.<br>
Thanks,<br>V<br><br></div></div>