Example #1
0
 def write(self, data, filepath):
     """ Write data to path as a sequence of '\\n' terminated lines.
         
         Args:
             data (various): any variable
             filepath (string): file path
         
         Notes:
             All data items are "pretty printed", i.e. they are split into lines
             according to content.
     """
     if (isinstance(data, list)):
         ut.write_strings(data, filepath)
     elif (isinstance(data, dict)):
         ut.write_strings(self._format_dict(data))
     elif (ut.is_string_type(data)):
         ut.write_file(data + '\n', filepath)
     else:
         raise ParametersError('text')
Example #2
0
 def write(self, data, filepath):
     """ Write data to path as a sequence of '\\n' terminated lines.
         
         Args:
             data (various): any variable
             filepath (string): file path
         
         Notes:
             All data items are "pretty printed", i.e. they are split into lines
             according to content.
     """
     if (isinstance(data, list)):
         ut.write_strings(data, filepath)
     elif (isinstance(data, dict)):
         ut.write_strings(self._format_dict(data))
     elif (ut.is_string_type(data)):
         ut.write_file(data + '\n', filepath)
     else:
         raise ParametersError('text')
Example #3
0
 def save(self, data, path):
     """ Save data as a JSON object coded in a string
     
         Args:
             data (various) any variable
             path (string) file path
             
         Variables will always be written as JSON objects, but lists will be
         output manually to prevent json.dumps from encoding them as a single
         string without line breaks.
     """
     if (isinstance(data, list)): # pretty print data as JSON
         data = [json.dumps(item) for item in data]
         '''
         for index in range(len(data)):
             item = data[index]
             item = json.dumps(item)
             data[index] = item
         '''
         ut.write_file('[\n' + ',\n'.join(data) + '\n]\n', path)
     else:
         ut.write_file(json.dumps(data) + '\n', path)
Example #4
0
 def save(self, data, path):
     """ Save data as a JSON object coded in a string
     
         Args:
             data (various) any variable
             path (string) file path
             
         Variables will always be written as JSON objects, but lists will be
         output manually to prevent json.dumps from encoding them as a single
         string without line breaks.
     """
     if (isinstance(data, list)):  # pretty print data as JSON
         data = [json.dumps(item) for item in data]
         '''
         for index in range(len(data)):
             item = data[index]
             item = json.dumps(item)
             data[index] = item
         '''
         ut.write_file('[\n' + ',\n'.join(data) + '\n]\n', path)
     else:
         ut.write_file(json.dumps(data) + '\n', path)