Sign in to follow this  
assainator

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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this