2011-03-07

Python: PyROOT + optparse

If for some reason you have to use PyROOT (in my case, I need to use TMVA), you probably still want to parse command line arguments for yourself, e.g. with optparse. To prevent PyROOT from scooping up the command line, import it like so:

import sys

tmpargv = sys.argv[:]             # [:] for a copy, not reference
sys.argv = []
from ROOT import gSystem, gROOT
from ROOT import TMVA             # otherwise I wouldn't be using ROOT!
sys.argv = tmpargv

from optparse import OptionParser

Et voilá, your command line is under control!

2 comments:

  1. import ROOT
    ROOT.PyConfig.IgnoreCommandLineOptions = True

    ReplyDelete
  2. Thanks, Ruggero! Luckily I'm not using ROOT at all anymore. :)

    ReplyDelete