python IO problem

Recommended Posts

assainator    685
heey all, at the moment i'm back to python and it's file IO. I have a list of strings that should be formatted and saved. At the moment this works and write the strings to a file
def writeProto(self, filename):
stream = open(filename, "w")
endstring = ""
for name in self.parent.finder.namelist:
#expObjType = self.parent.finder.GetType(expObj)
#expObjID = self.parent.finder.GetID(expObj)

#the name is shown correctly
print name

#enstring = "o %s" % (str(name))

#write the damn thing to a file
stream.write(name)
stream.write("\n")

#close the file
stream.close()


But as soon as i change it to this it doesn't write a thing but it still prints the names
def writeProto(self, filename):
stream = open(filename, "w")
endstring = ""
for name in self.parent.finder.namelist:
#expObjType = self.parent.finder.GetType(expObj)
#expObjID = self.parent.finder.GetID(expObj)

#the name is still shown correct
print name

enstring = "o %s" % (str(name))

#write the damn thing to a file
stream.write(endstring)
stream.write("\n")

#close the file
stream.close()


Can anybody see why it doesn't work? thanks in advance, assainator

Share on other sites
SiCrane    11839
enstring is not the same identifier as endstring.