<div class="gmail_quote">On Tue, Oct 4, 2011 at 8:48 AM, lina <span dir="ltr">&lt;<a href="mailto:lina.lastname@gmail.com">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 class="im">    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><br>That&#39;s because in this line:<br></div></div><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>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><br>(in other words, split fileName, take just the first part, and add &quot;.txt&quot; to the end of it.)<br>