MCPcopy Create free account
hub / github.com/modelscope/modelscope / dumps

Function dumps

modelscope/fileio/io.py:107–127  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

105
106
107def 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)

Callers 1

test_formatMethod · 0.90

Calls 1

dumpsMethod · 0.45

Tested by 1

test_formatMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…