class, mode='recreate')[source]

A subclass of ROOT’s TMemFile [1]




>>> from import MemFile
>>> f = MemFile()

Like ROOT’s Close but reverts to the gDirectory before this file was opened.


cd to the gDirectory before this file was open.


Like ROOT’s Close but reverts to the gDirectory before this file was opened.

copytree(dest_dir, src=None, newname=None, exclude=None, overwrite=False)

Copy this directory or just one contained object into another directory.


dest_dir : string or Directory

The destination directory.

src : string, optional (default=None)

If src is None then this entire directory is copied recursively otherwise if src is a string path to an object relative to this directory, only that object will be copied. The copied object can optionally be given a newname.

newname : string, optional (default=None)

An optional new name for the copied object.

exclude : callable, optional (default=None)

exclude can optionally be a function which takes (path, object_name) and if returns True excludes objects from being copied if the entire directory is being copied recursively.

overwrite : bool, optional (default=False)

If True, then overwrite existing objects with the same name.

find(regexp, negate_regexp=False, class_pattern=None, find_fnc=<function search>, refresh_cache=False)

yield the full path of the matching regular expression and the match itself


Return a list of the keys in this directory.


latest : bool, optional (default=False)

If True then return a list of keys with unique names where only the key with the highest cycle number is included where multiple keys exist with the same name.


keys : list

List of keys

mkdir(path, title='', recurse=False)

Make a new directory. If recurse is True, create parent directories as required. Return the newly created TDirectory.


Return an iterater over all objects in this directory which are instances of cls. By default, iterate over all objects (cls=None).


cls : a class, optional (default=None)

If a class is specified, only iterate over objects that are instances of this class.


A generator over the objects in this directory.


$ rootpy browse myfile.root

In [1]: list(f1.objects(R.Directory)) Out[1]: [Directory(‘mydirectory’)]

rm(path, cycle=';*')

Delete an object at path relative to this directory

walk(top=None, path=None, depth=0, maxdepth=-1, class_ref=None, class_pattern=None, return_classname=False, treat_dirs_as_objs=False)

Walk the directory structure and content in and below a directory. For each directory in the directory tree rooted at top (including top itself, but excluding ‘.’ and ‘..’), yield a 3-tuple dirpath, dirnames, filenames.


top : string, optional (default=None)

A path to a starting directory relative to this directory, otherwise start at this directory.

path : string, optional (default=None)

A path prepended as a prefix on the dirpath. This argument is used internally as the recursion traverses down through subdirectories.

depth : int, optional (default=0)

The current depth, used internally as the recursion traverses down through subdirectories.

max_depth : int, optional (default=-1)

The maximum depth in the directory hierarchy to traverse. There is no limit applied by default.

class_ref : class, optional (default=None)

If not None then only include objects that are instances of class_ref.

class_pattern : string, optional (default=None)

If not None then only include objects in filenames with class names that match class_pattern. class_pattern should be a Unix shell-style wildcarded string.

return_classname : bool, optional (default=False)

If True, then each entry in filenames is a tuple of the form (filename, classname).

treat_dirs_as_objs : bool, optional (default=False)

If True, filenames contains directories as well.


dirpath, dirnames, filenames : iterator

An iterator over the 3-tuples dirpath, dirnames, filenames. dirpath is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding ‘.’ and ‘..’). filenames is a list of the names of the non-directory files/objects in dirpath.


The names in the lists are just names, with no path components. To get a full path (which begins with top) to a file or directory in dirpath, use os.path.join(dirpath, name).