<div class="gmail_quote">On Tue, Oct 4, 2011 at 8:48 AM, lina <span dir="ltr"><<a href="mailto:lina.lastname@gmail.com">lina.lastname@gmail.com</a>></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]==".xpm":<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("fileName.txt","w").write(index,"-----",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'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("fileName.txt","w").write(index,"-----",r)<br>
</blockquote>you put "fileName.txt" 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] + ".txt","w").write(index,"-----",r)<br></blockquote><br>(in other words, split fileName, take just the first part, and add ".txt" to the end of it.)<br>