python IO problem

Started by
0 comments, last by SiCrane 14 years, 1 month ago
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
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

Advertisement
enstring is not the same identifier as endstring.

This topic is closed to new replies.

Advertisement