<br><br><div class="gmail_quote">On Wed, Oct 5, 2011 at 12:59 AM, Marc Tompkins <span dir="ltr">&lt;<a href="mailto:marc.tompkins@gmail.com">marc.tompkins@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">On Tue, Oct 4, 2011 at 8:48 AM, lina <span dir="ltr">&lt;<a href="mailto:lina.lastname@gmail.com" target="_blank">lina.lastname@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="gmail_quote"><div><div>    if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==&quot;.xpm&quot;:<br>        filedata = open(fileName)<br>        text=filedata.readlines()<br></div>        for line in text[0:]:<br>

            result.append({t:line.strip().count(t) for t in tokens})<br>
        for index,r in enumerate(result):<br>           outfiledata=open(&quot;fileName.txt&quot;,&quot;w&quot;).write(index,&quot;-----&quot;,r)<br>I still have problem using the value of the fileName,<br><br>here the output is fileName.txt, not $fileName.txt which is supposed to be 1.txt following input 1.xpm<br>

</div></div></blockquote></div><div><br>That&#39;s because in this line:<br></div></div><div class="im"><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">
           outfiledata=open(&quot;fileName.txt&quot;,&quot;w&quot;).write(index,&quot;-----&quot;,r)<br>
</blockquote></div>you put &quot;fileName.txt&quot; in quotes - which makes it a literal, not a variable. <br><br>Try this:<br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">

           outfiledata=open(os.path.splitext(fileName)[0] + &quot;.txt&quot;,&quot;w&quot;).write(index,&quot;-----&quot;,r)<br></blockquote>Thanks, it works.  I understand it now.<br>(in other words, split fileName, take just the first part, and add &quot;.txt&quot; to the end of it.) </blockquote>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br><br>lina<br><br><br>