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 the fileType next, .__registry and 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 .__registry and are forced to conform to the prescribed API. The metaclass takes cares 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, ….for now we’ll just return an instance of W on mode=’r’ …. on mode=’w’, .write will expect an instance of W

__init__(self, dataPath='', mode='r', dataFormat=None)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self[, dataPath, mode, dataFormat])

Initialize self.

cast(self, key, typ)

cast key as typ

check()

Prints the contents of the registry

close(self)

subclasses should clean themselves up and then call this method

flush(self)

get(self, n)

Seeks the file to n and returns n If .ids is set n should be an id, else, n should be an offset

getType(dataPath, mode[, dataFormat])

Parse the dataPath and return the data type

open(\*args, \*\*kwargs)

Alias for FileIO()

read(self[, n])

Read at most n objects, less if read hits EOF if size is negative or omitted read all objects until EOF returns None if EOF is reached before any objects.

seek(self, n)

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

tell(self)

Return id (or offset) of next object

truncate(self[, size])

Should be implemented by subclasses and redefine this doc string

write(self, obj)

Must be implemented by subclasses that support ‘w’ subclasses should increment .pos subclasses should also check if obj is an instance of type(list) and redefine this doc string

Attributes

by_row

ids

rIds

property by_row
cast(self, key, typ)[source]

cast key as typ

classmethod check()[source]

Prints the contents of the registry

close(self)[source]

subclasses should clean themselves up and then call this method

flush(self)[source]
get(self, n)[source]

Seeks the file to n and returns n If .ids is set n should be an id, else, n should be an offset

static getType(dataPath, mode, dataFormat=None)[source]

Parse the dataPath and return the data type

property ids
classmethod open(*args, **kwargs)[source]

Alias for FileIO()

property rIds
read(self, n=-1)[source]

Read at most n objects, less if read hits EOF if size is negative or omitted read all objects until EOF returns None if EOF is reached before any objects.

seek(self, n)[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

tell(self)[source]

Return id (or offset) of next object

truncate(self, size=None)[source]

Should be implemented by subclasses and redefine this doc string

write(self, obj)[source]

Must be implemented by subclasses that support ‘w’ subclasses should increment .pos subclasses should also check if obj is an instance of type(list) and redefine this doc string