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

Method write_text

modelscope/fileio/file.py:307–321  ·  view source on GitHub ↗

Write data to a given ``filepath`` with 'w' mode. Note: ``write_text`` will create a directory if the directory of ``filepath`` does not exist. Args: obj (str): Data to be written. filepath (str or Path): Path to write data.

(obj: str, uri: str, encoding: str = 'utf-8')

Source from the content-addressed store, hash-verified

305
306 @staticmethod
307 def write_text(obj: str, uri: str, encoding: str = 'utf-8') -> None:
308 """Write data to a given ``filepath`` with 'w' mode.
309
310 Note:
311 ``write_text`` will create a directory if the directory of
312 ``filepath`` does not exist.
313
314 Args:
315 obj (str): Data to be written.
316 filepath (str or Path): Path to write data.
317 encoding (str): The encoding format used to open the ``filepath``.
318 Default: 'utf-8'.
319 """
320 storage = File._get_storage(uri)
321 return storage.write_text(obj, uri)
322
323 @contextlib.contextmanager
324 def as_local_path(uri: str) -> Generator[Union[str, Path], None, None]:

Callers 3

dumpFunction · 0.45
test_context_managerMethod · 0.45
setUpMethod · 0.45

Calls 1

_get_storageMethod · 0.80

Tested by 2

test_context_managerMethod · 0.36
setUpMethod · 0.36