Unable to write to a text file
- by chrissygormley
Hello,
I am running some tests and need to write to a file. When I run the test's the open = (file, 'r+') does not write to the file. The test script is below:
class GetDetailsIP(TestGet):
    def runTest(self):
        self.category = ['PTZ']
        try:
            # This run's and return's a value
            result = self.client.service.Get(self.category) 
            mylogfile = open("test.txt", "r+")
            print >>mylogfile, result
            result = ("".join(mylogfile.readlines()[2]))
            result = str(result.split(':')[1].lstrip("//").split("/")[0])
            mylogfile.close()
        except suds.WebFault, e:                        
            assert False
        except Exception, e:
            pass
        finally:
            if 'result' in locals():
                self.assertEquals(result, self.camera_ip)
            else:
                assert False
When this test run's, no value has been entered into the text file and a value is returned in the variable result.
I havw also tried mylogfile.write(result). If the file does not exist is claim's the file does not exist and doesn't create one.
Could this be a permission problem where python is not allowed to create a file? I have made sure that all other read's to this file are closed so I the file should not be locked.
Can anyone offer any suggestion why this is happening?
Thanks