Пример #1
0
 def store_coordinates(self, coordinates, file_name=uuid1().__str__()):
     '''
     Stores the coordinates object into a file. If the file name is not informed, a new unique name will be
     generated. Once the store operation is done, this function returns the file name used for future
     actions.
     
     @param coordinates: to be stored.
     @param file_name: has a default value when not informed. It uses uuid1() function to generate the file name.
     '''
     file = None
     try:
         file = fileOperation.open_file(file_name)
         fileOperation.write_to_file(file, coordinates.__str__() + '\n')
     except IOError as error:
         '''
         Logs errors occurred during store operation.
         '''
         self.error(error)
         raise error
     else:
         '''
         If nothing wrong occurred, log info.
         This statement is only executed if there is no return statement within the try block.
         '''
         self.info('Coordinates stored successfully.')
         return file_name
     finally:
         '''
         Closes the stream and flushes the file.
         '''
         try:
             if file:
                 fileOperation.close_file(file)
         except IOError as error:
             self.error(error)
Пример #2
0
 def store_coordinates(self, coordinates, file_name = uuid1().__str__()):
     '''
     Stores the coordinates object into a file. If the file name is not informed, a new unique name will be
     generated. Once the store operation is done, this function returns the file name used for future
     actions.
     
     @param coordinates: to be stored.
     @param file_name: has a default value when not informed. It uses uuid1() function to generate the file name.
     '''
     file = None
     try:
         file = fileOperation.open_file(file_name)
         fileOperation.write_to_file(file, coordinates.__str__() + '\n')
     except IOError as error:
         '''
         Logs errors occurred during store operation.
         '''
         self.error(error)
         raise error
     else:
         '''
         If nothing wrong occurred, log info.
         This statement is only executed if there is no return statement within the try block.
         '''
         self.info('Coordinates stored successfully.')
         return file_name
     finally:
         '''
         Closes the stream and flushes the file.
         '''
         try:
             if file:
                 fileOperation.close_file(file)
         except IOError as error:
             self.error(error)
Пример #3
0
All calls in this module will use the file object wrapped by the module fileOperation.
'''
'''
Opens/Creates a file using the given name and default arguments.
'''
file = fileOperation.open_file('python_test.txt')
'''
Writes into the file.
'''
fileOperation.write_to_file(file, 'First line test\n')
fileOperation.write_to_file(file, 'Second line test\n')
fileOperation.write_to_file(file, 'Third line test\n')
'''
Flushes the file content and closes it.
'''
fileOperation.close_file(file)
'''
Open the already created file on Read mode.
'''
file = fileOperation.open_file('python_test.txt', 'r')
'''
Prints the first line from the file.
'''
print fileOperation.read_line(file)
'''
Reads the remaining lines from the file.
'''
lines = fileOperation.read_lines(file)

for l in lines:
    print l
Пример #4
0
"""
Opens/Creates a file using the given name and default arguments.
"""
file = fileOperation.open_file("python_test.txt")

"""
Writes into the file.
"""
fileOperation.write_to_file(file, "First line test\n")
fileOperation.write_to_file(file, "Second line test\n")
fileOperation.write_to_file(file, "Third line test\n")

"""
Flushes the file content and closes it.
"""
fileOperation.close_file(file)

"""
Open the already created file on Read mode.
"""
file = fileOperation.open_file("python_test.txt", "r")

"""
Prints the first line from the file.
"""
print fileOperation.read_line(file)

"""
Reads the remaining lines from the file.
"""
lines = fileOperation.read_lines(file)