<div>Thanks,</div>
<div>&nbsp;</div>
<div>it&#39;s strange, it works within a script defined at the top, but if I try to import it from a module it fails:</div>
<div><br>NameError: name &#39;files&#39; is not defined<br>&nbsp;</div>
<div><br>&nbsp;</div>
<div><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">Aditya Lal</b> &lt;<a href="mailto:aditya.n.lal@gmail.com">aditya.n.lal@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div><span class="e" id="q_115e276e7a4e3012_0"><br><br>
<div><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">John</b> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:washakie@gmail.com" target="_blank">washakie@gmail.com</a>&gt; wrote: 
</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Note, i need the ns+1 because the &#39;source files are not zero indexed.<br><br>
<div><span><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">John</b> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:washakie@gmail.com" target="_blank">washakie@gmail.com </a>
&gt; wrote:</span> </span>
<div><span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Here&#39;s where I am:</div>
<div>&nbsp;</div>
<div>
<p><font face="courier new,monospace">def source(filename, vList):<span><br>&nbsp;&quot;&quot;&quot; takes a file object and a list of variables as input &quot;&quot;&quot;<br></span><span>&nbsp;import re<br>&nbsp;# Read the file <br></span>
&nbsp;fid=open(filename,&#39;r&#39;) <br>&nbsp;lines = fid.readlines()<br>&nbsp;fid.close()<br>&nbsp;#how many variables<br>&nbsp;ns=len(lines)/len(vList)<br>&nbsp;#predefine the varibles<br>&nbsp;for v in vList:<br>&nbsp;&nbsp;exec( &#39;global %s ; %s = [0]*(ns+1)&#39; % (v, v)) 
<span><br>&nbsp;&nbsp;<br>&nbsp;# Make it python friendly: put all values in &#39;single quotes&#39; <br></span><span>&nbsp;cmd = &#39;\n&#39;.join([re.sub( r&#39;^([^=]+)=(.*)$&#39;, r&quot;\1=&#39;\2&#39;&quot;, v) for v in lines]) <br></span>
&nbsp;exec(cmd)<br>&nbsp;for v in vList:<br>&nbsp;&nbsp;exec( &#39;%s=%s[1:]&#39; % (v,v))<br>&nbsp;<br>source(&#39;infile.py&#39;,[&#39;files&#39;,&#39;nfiles&#39;,&#39;nreleases&#39;]) </font></p>
<p><font face="courier new,monospace">print files<br>print nreleases<br>print nfiles</font></p>
<p><font face="Courier New"></font>&nbsp;</p>
<p><font face="Courier New">But oddly, my output is:</font></p>
<p>[0, &#39;ASP_200603&#39;, &#39;ASP_200604&#39;, &#39;ASP_200605&#39;]<br>[0, &#39;248&#39;, &#39;240&#39;, &#39;248&#39;]<br>[0, &#39;3&#39;, &#39;3&#39;, &#39;3&#39;]</p>
<p>&nbsp;</p>
<p>So, I am not properly getting rid of the list[0], is it something with the &#39;global&#39; nature of the vairables... it looks like it&#39;s only changing locallly in my source function.<br></p></div></blockquote></span>
</div></div><br><br clear="all">
<div><span><br>-- <br>Configuration<br>``````````````````````````<br>Plone 2.5.3-final,<br>CMF-1.6.4,<br>Zope (Zope 2.9.7-final, python 2.4.4, linux2),<br>Five 1.4.1,<br>Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1
 20070105 (Red Hat 4.1.1-51)],<br>PIL 1.1.6 </span></div></blockquote></div></span></div>
<div><br>I think you need to define the variable global again otherwise it will re-assign the object in local space.</div>
<div>&nbsp;</div>
<div>exec( &quot;global %s ; %s = %s[1:]&quot; % (v,v,v) )<br clear="all"><br>-- <br>Aditya </div></blockquote></div><br><br clear="all"><br>-- <br>Configuration<br>``````````````````````````<br>Plone 2.5.3-final,<br>CMF-1.6.4
,<br>Zope (Zope 2.9.7-final, python 2.4.4, linux2),<br>Five 1.4.1,<br>Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)],<br>PIL 1.1.6