I/O
momapy.io
Base classes and functions for reading and writing maps
Classes:
Name | Description |
---|---|
IOResult |
Base class for I/O results |
Reader |
Base class for readers |
ReaderResult |
Base class for reader results |
Writer |
Base class for writers |
WriterResult |
Base class for writer results |
Functions:
Name | Description |
---|---|
read |
Read a map file and return a reader result using the given registered reader. If no reader is given, will check for an appropriate reader among the registered readers, using the |
register_reader |
Register a reader |
register_writer |
Register a writer |
write |
Write an object to a file and return a writer result using the given registered writer |
Reader
Bases: ABC
Base class for readers
Methods:
Name | Description |
---|---|
check_file |
Return |
read |
Read a file and return a reader result using the reader |
check_file
classmethod
read
abstractmethod
classmethod
read(file_path: str | PathLike, **options) -> ReaderResult
ReaderResult
dataclass
Writer
Bases: ABC
Base class for writers
Methods:
Name | Description |
---|---|
write |
Write an object to a file and return a writer result using the writer |
write
abstractmethod
classmethod
write(obj: Any, file_path: str | PathLike, **options) -> WriterResult
Write an object to a file and return a writer result using the writer
WriterResult
dataclass
read
read(file_path: str | PathLike, reader: str | None = None, **options) -> ReaderResult
Read a map file and return a reader result using the given registered reader. If no reader is given, will check for an appropriate reader among the registered readers, using the check_file
method of each reader. If there is more than one appropriate reader, will use the first one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | PathLike
|
The path of the file to read |
required |
reader
|
str | None
|
The registered reader |
None
|
options
|
Options to be passed to the reader |
{}
|
Returns:
Type | Description |
---|---|
ReaderResult
|
A reader result |
Source code in src/momapy/io.py
register_reader
register_writer
write
write(obj: Any, file_path: str | PathLike, writer: str, **options) -> WriterResult
Write an object to a file and return a writer result using the given registered writer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to write |
required |
file_path
|
str | PathLike
|
The path of the file to write to |
required |
writer
|
str
|
The registered writer |
required |
options
|
Options to be passed to the writer |
{}
|
Returns:
Type | Description |
---|---|
WriterResult
|
A writer result |