larray.Session.load¶
-
Session.load(fname, names=None, engine='auto', display=False, **kwargs)[source]¶ Loads array objects from a file, or several .csv files.
WARNING: never load a file using the pickle engine (.pkl or .pickle) from an untrusted source, as it can lead to arbitrary code execution.
Parameters: fname : str
This can be either the path to a single file, a path to a directory containing .csv files or a pattern representing several .csv files.
names : list of str, optional
List of arrays to load. If fname is None, list of paths to CSV files. Defaults to all valid objects present in the file/directory.
engine : {‘auto’, ‘pandas_csv’, ‘pandas_hdf’, ‘pandas_excel’, ‘xlwings_excel’, ‘pickle’}, optional
Load using engine. Defaults to ‘auto’ (use default engine for the format guessed from the file extension).
display : bool, optional
Whether or not to display which file is being worked on. Defaults to False.
Examples
In one module
>>> arr1, arr2, arr3 = ndtest((2, 2)), ndtest(4), ndtest((3, 2)) >>> s = Session([('arr1', arr1), ('arr2', arr2), ('arr3', arr3)]) >>> s.save('input.h5')
In another module
>>> s = Session() >>> s.load('input.h5', ['arr1', 'arr2', 'arr3']) >>> arr1, arr2, arr3 = s['arr1', 'arr2', 'arr3'] >>> # only if you know the order of arrays stored in session >>> arr1, arr2, arr3 = s.values()
Using .csv files (assuming the same session as above)
>>> s.save('data') >>> s = Session() >>> # load all .csv files starting with "output" in the data directory >>> s.load('data') >>> # or equivalently in this case >>> s.load('data/arr*.csv')