4.11.3. io Package

4.11.3.1. io Package

exception rootpy.io.DoesNotExist[source]

Bases: exceptions.Exception

4.11.3.2. file Module

This module enhances IO-related ROOT functionality

class rootpy.io.file.Directory(name, title, *args, **kwargs)[source]

Bases: rootpy.io.file._DirectoryBase, TDirectoryFile

Inherits from TDirectory

class rootpy.io.file.File(*args, **kwargs)[source]

Bases: rootpy.io.file._DirectoryBase, TFile

Wrapper for TFile that adds various convenience functions.

>>> from rootpy.test import filename
>>> f = File(filename, 'read')

4.11.3.3. utils Module

This module contains os.path/walk-like utilities for the ROOT TFile ‘filesystem’

rootpy.io.utils.cp(src, dest_dir, newname=None, exclude=None)[source]

Copy an object into another TDirectory.

[src] or [dest_dir] can either be passed as path strings, or as ROOT objects themselves.

If <src> is a TDirectory, the objects will be copied recursively.

[exclude] can optionally be a function which takes (path, object_name) and if returns True excludes objects from being copied.

The copied object can optionally be given a [newname].

rootpy.io.utils.mkdir(dest_path, recurse=False)[source]

Make a new directory relative to the CWD

If recurse is True, create parent directories as required.

Return the newly created TDirectory

rootpy.io.utils.rm(path_to_object, cycle=';*')[source]

Delete an object in a TDirectory

You must pass the path string, relative to the CWD

rootpy.io.utils.splitfile(path)[source]
rootpy.io.utils.walk(tdirectory, top=None, path=None, depth=0, maxdepth=-1, class_pattern=None)[source]

For each directory in the directory tree rooted at top (including top itself, but excluding ‘.’ and ‘..’), yields a 3-tuple

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. Note that 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, do os.path.join(dirpath, name).