On Wed, Oct 5, 2011 at 12:59 AM, Marc Tompkins <marc.tompk...@gmail.com>wrote:
> On Tue, Oct 4, 2011 at 8:48 AM, lina <lina.lastn...@gmail.com> wrote: > >> if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm": >> filedata = open(fileName) >> text=filedata.readlines() >> for line in text[0:]: >> result.append({t:line.strip().count(t) for t in tokens}) >> for index,r in enumerate(result): >> outfiledata=open("fileName.txt","w").write(index,"-----",r) >> I still have problem using the value of the fileName, >> >> here the output is fileName.txt, not $fileName.txt which is supposed to be >> 1.txt following input 1.xpm >> > > That's because in this line: > >> outfiledata=open("fileName.txt","w").write(index,"-----",r) >> > you put "fileName.txt" in quotes - which makes it a literal, not a > variable. > > Try this: > >> outfiledata=open(os.path.splitext(fileName)[0] + >> ".txt","w").write(index,"-----",r) >> > Thanks, it works. I understand it now. > (in other words, split fileName, take just the first part, and add ".txt" > to the end of it.) > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Best Regards, lina
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor