PyROOT: Overloaded constructor not available in derived TFile class

Hi all,

I am trying to create a new class in PyROOT that inherits from TFile:

import ROOT

class File(ROOT.TFile):
    def __init__(self, filename, mode=""):
        super().__init__(filename, mode)

   # Advanced functions follow here...

Unfortunately, it seems that it does not properly handle the overloaded TFile constructors, because when I try to create an instance of this file via f = File("file.root", "READ) the error message

super().__init__(filename, mode)
TypeError: none of the 2 overloaded methods succeeded. Full details:
  TFile::TFile() =>
    TypeError: takes at most 0 arguments (2 given)
  no constructor available for 'TFile'

It does not even show the second C++ TFile constructor in this message which accepts a filename and the mode in which the file is opened (as well as the title and compression, which I don’t care about in the derived class).

Additional notes:

  • It does not help to omit the __init__ function.
  • Running f = ROOT.TFile("file.root", "READ) (of course) works as expected
  • ROOT Version: 6.22/00
  • Python Version: 3.7.6

Looking forward for your help,

We’ll need @etejedor for this who’s back only next week. Please ping us on Tuesday should you not have heard back!


This is most probably a bug in the 6.22/00 version you are using, please consider upgrading to 6.24.

I just tried your code with master and it works fine.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.