<br><br><div class="gmail_quote">On Wed, Oct 5, 2011 at 12:59 AM, Marc Tompkins <span dir="ltr"><<a href="mailto:marc.tompkins@gmail.com">marc.tompkins@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 class="im">On Tue, Oct 4, 2011 at 8:48 AM, lina <span dir="ltr"><<a href="mailto:lina.lastname@gmail.com" target="_blank">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> 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><div><br>That'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("fileName.txt","w").write(index,"-----",r)<br>
</blockquote></div>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>Thanks, it works. I understand it now.<br>(in other words, split fileName, take just the first part, and add ".txt" 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>