Data.load¶
- classmethod Data.load(*args, **kargs)¶
Create a new
DataFile
from a file on disc guessing a better subclass if necessary.- Parameters:
filename (string or None) – path to file to load
- Keyword Arguments:
auto_load (bool) – If True (default) then the load routine tries all the subclasses of
DataFile
in turn to load the filefiletype (
DataFile
, str) – If not none then tries using filetype as the loader.loaded_class (bool) – If True, the return object is kept as the class that managed to load it, otherwise it is copied into a
Stoner.Data
object. (Default False)
- Returns:
(Data) – A new instance of
Stoner.Data
or a s subclass ofStoner.DataFile
if loaded_class is True.
Note
If filetype is a string, then it is first tried as an exact match to a subclass name, otherwise it is used as a partial match and the first class in priority order is that matches is used.
Some subclasses can be found in the
Stoner.formats
package.Each subclass is scanned in turn for a class attribute priority which governs the order in which they are tried. Subclasses which can make an early positive determination that a file has the correct format can have higher priority levels. Classes should return a suitable exception if they fail to load the file.
If no class can load a file successfully then a StonerUnrecognisedFormat exception is raised.