earthkit.data.targets.file¶
Attributes¶
Classes¶
File target. |
Module Contents¶
- class earthkit.data.targets.file.FileTarget(file=None, *, append=False, **kwargs)¶
Bases:
earthkit.data.targets.SimpleTargetFile target.
- Parameters:
file (
str,file-like,None) – The file path or file-like object to write to. When None, tries to guess the file name from thedataif it is passed as a kwarg. When the file name cannot be constructed, a ValueError is raised. Whenfileis a path, a file object is automatically created and closed when the target is closed. Whenfileis a file object, its ownership is not transferred to the target. As a consequence, the file object is not closed when the target is closed, even ifcloseis called explicitly.append (
bool) – If True, the file is opened in append mode. Only used iffileis a path.**kwargs – Additional keyword arguments passed to the parent class.
- Raises:
ValueError –
- append = False¶
- close()¶
Close the file if
FileTargetwas created with a file path.If
FileTargetwas created with a file object this call has no effect. The target will not be able to write anymore.- Raises:
ValueError –
- property closed¶
True if the target is closed, False otherwise.
- ext = None¶
- filename = None¶
- fileobj = None¶
- flush()¶
Flush the file.
- Raises:
ValueError –
- write(data=None, **kwargs)¶
Write data to the target using the given encoder.
- Parameters:
data (
obj,None) – The data object to write. If None, the encoder will use all the other arguments to generate the data to write.encoder (
str,Encoder,None) – The encoder to use to encode the data. When a string is passed, the encoder is looked up in the available encoders. When None, the encoder theTargetwas created with will be used if available. Otherwise, the encoder will be determined from the data to write (if possible) or from theTargetproperties.template (
obj,None) – The template to use to encode the data. When None, the template theTargetwas created with will be used if available.metadata (
dict,None) – Metadata to pass to the encoder.**kwargs (
dict) – Other keyword arguments passed to the encoder.
- Raises:
ValueError –
- earthkit.data.targets.file.target¶