libpysal.io.fileio.FileIO¶
- class libpysal.io.fileio.FileIO(dataPath='', mode='r', dataFormat=None)[source]¶
Metaclass for supporting spatial data file read and write.
How this works:
FileIO.open(\*args) == FileIO(\*args)When creating a new instance of FileIO the
.__new__method intercepts..__new__parses the filename to determine thefileType. Next,.__registryand checked for that type. Each type supports one or more modes (['r', 'w', 'a', etc.]). If we support the type and mode, an instance of the appropriate handler is created and returned. All handlers must inherit from this class, and by doing so are automatically added to the.__registryand are forced to conform to the prescribed API. The metaclass takes care of the registration by parsing the class definition. It doesn’t make much sense to treat weights in the same way as shapefiles and dbfs, so…… for now we’ll just return an instance of W on
mode='r'.… on
mode='w',.writewill expect an instance of W.
Methods
__init__([dataPath, mode, dataFormat])cast(key, typ)Cast
keyastyp.check()Prints the contents of the registry.
close()Subclasses should clean themselves up and then call this method.
flush()get(n)Seeks the file to
nand returnsn.getType(dataPath, mode[, dataFormat])Parse the
dataPathand return the data type.open(*args, **kwargs)Alias for
FileIO().read([n])Read at most
nobjects, less if read hits EOF.seek(n)Seek the FileObj to the beginning of the
n'th record.tell()Return ID (or offset) of next object.
truncate([size])Should be implemented by subclasses and redefine this doc string.
write(obj)Must be implemented by subclasses that support 'w' subclasses Should increment
.pos.Attributes
- property by_row¶
- get(n: int) list[source]¶
Seeks the file to
nand returnsn. If.idsis setnshould be an id, else,nshould be an offset.
- static getType(dataPath: str, mode: str, dataFormat=None) str[source]¶
Parse the
dataPathand return the data type.
- property ids¶
- read(n=-1) list | None[source]¶
Read at most
nobjects, less if read hits EOF. If size is negative or omitted read all objects until EOF. ReturnsNoneif EOF is reached before any objects.- Raises:
StopIterationRaised at the EOF.
- seek(n: int)[source]¶
Seek the FileObj to the beginning of the
n’th record. If IDs are set, seeks to the beginning of the record at ID,n.
- truncate(size=None)[source]¶
Should be implemented by subclasses and redefine this doc string.
- Raises: