File Objects¶
-
class
exdir.core.
File
(directory, mode=None, allow_remove=False, name_validation=None, plugins=None)[source]¶ Bases:
exdir.core.group.Group
Exdir file object. A File is a special type of
Group
. SeeGroup
for documentation of inherited functions.To create a File, call the File constructor with the name of the File you wish to create:
>>> import exdir >>> import numpy as np >>> f = exdir.File("mytestfile.exdir")
The
File
objectf
now points to the root folder in the exdir file structure. You can add groups and datasets to it as follows:>>> my_group = f.require_group("my_group") >>> a = np.arange(100) >>> dset = f.require_dataset("my_data", data=a)
The data is immediately written to disk.
- Parameters
directory – Name of the directory to be opened or created as an Exdir File.
mode (str, optional) – A file mode string that defines the read/write behavior. See open() for information about the different modes.
allow_remove (bool) – Set to True if you want mode ‘w’ to remove existing trees if they exist. This False by default to avoid removing entire directory trees by mistake.
name_validation (str, function, optional) – Set the validation mode for names. Can be a function that takes a name and returns True if the name is valid or one of the following built-in validation modes:
‘strict’: only allow numbers, lowercase letters, underscore (_) and dash (-)
‘simple’: allow numbers, lowercase letters, uppercase letters, underscore (_) and dash (-), check if any file exists with same name in any case.
‘thorough’: verify if name is safe on all platforms, check if any file exists with same name in any case.
‘none’: allows any filename
The default is ‘thorough’.
plugins (list, optional) – A list of instantiated plugins or modules with a plugins() function that returns a list of plugins.
-
close
()[source]¶ Closes the File object. Sets the OpenMode to FILE_CLOSED which denies access to any attribute or child