Dump data to json/yaml strings or files. This method provides a unified api for dumping data as strings or to files. Args: obj (any): The python object to be dumped. format (str, optional): Same as file_format :func:`load`. Examples: >>> dumps('hello world', 'j
(obj, format, **kwargs)
| 105 | |
| 106 | |
| 107 | def dumps(obj, format, **kwargs): |
| 108 | """Dump data to json/yaml strings or files. |
| 109 | |
| 110 | This method provides a unified api for dumping data as strings or to files. |
| 111 | |
| 112 | Args: |
| 113 | obj (any): The python object to be dumped. |
| 114 | format (str, optional): Same as file_format :func:`load`. |
| 115 | |
| 116 | Examples: |
| 117 | >>> dumps('hello world', 'json') # json |
| 118 | >>> dumps('hello world', 'yaml') # yaml |
| 119 | |
| 120 | Returns: |
| 121 | bool: True for success, False otherwise. |
| 122 | """ |
| 123 | if format not in format_handlers: |
| 124 | raise TypeError(f'Unsupported format: {format}') |
| 125 | |
| 126 | handler = format_handlers[format] |
| 127 | return handler.dumps(obj, **kwargs) |
searching dependent graphs…