# pydicom.filewriter.write_dataset

pydicom.filewriter.write_dataset(fp: DicomIO, dataset: Dataset, parent_encoding: str | list[str] = 'iso8859') → int

  Encode dataset and write the encoded data to fp.

  Encoding

  The dataset is encoded as specified by (in order of priority):

  - `fp.is_implicit_VR` and `fp.is_little_endian`.

  - `dataset.is_implicit_VR` and `dataset.is_little_endian`

  - If dataset has been decoded from a file or buffer then `original_encoding`.

  Parameters:

    - fp (pydicom.filebase.DicomIO) – The file-like to write the encoded dataset to.

    - dataset (pydicom.dataset.Dataset) – The dataset to be encoded.

    - parent_encoding (str | List[str], optional) – The character set to use for encoding strings, defaults to `"iso8859"`.

  Returns:

    The number of bytes written to fp.

  Return type:

    int