<div>Thanks,</div>
<div> </div>
<div>it'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 'files' is not defined<br> </div>
<div><br> </div>
<div><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">Aditya Lal</b> <<a href="mailto:aditya.n.lal@gmail.com">aditya.n.lal@gmail.com</a>> 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> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:washakie@gmail.com" target="_blank">washakie@gmail.com</a>> 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 'source files are not zero indexed.<br><br>
<div><span><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">John</b> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:washakie@gmail.com" target="_blank">washakie@gmail.com </a>
> 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's where I am:</div>
<div> </div>
<div>
<p><font face="courier new,monospace">def source(filename, vList):<span><br> """ takes a file object and a list of variables as input """<br></span><span> import re<br> # Read the file <br></span>
fid=open(filename,'r') <br> lines = fid.readlines()<br> fid.close()<br> #how many variables<br> ns=len(lines)/len(vList)<br> #predefine the varibles<br> for v in vList:<br> exec( 'global %s ; %s = [0]*(ns+1)' % (v, v))
<span><br> <br> # Make it python friendly: put all values in 'single quotes' <br></span><span> cmd = '\n'.join([re.sub( r'^([^=]+)=(.*)$', r"\1='\2'", v) for v in lines]) <br></span>
exec(cmd)<br> for v in vList:<br> exec( '%s=%s[1:]' % (v,v))<br> <br>source('infile.py',['files','nfiles','nreleases']) </font></p>
<p><font face="courier new,monospace">print files<br>print nreleases<br>print nfiles</font></p>
<p><font face="Courier New"></font> </p>
<p><font face="Courier New">But oddly, my output is:</font></p>
<p>[0, 'ASP_200603', 'ASP_200604', 'ASP_200605']<br>[0, '248', '240', '248']<br>[0, '3', '3', '3']</p>
<p> </p>
<p>So, I am not properly getting rid of the list[0], is it something with the 'global' nature of the vairables... it looks like it'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> </div>
<div>exec( "global %s ; %s = %s[1:]" % (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