# AttributeError: 'TObject' object has no attribute 'SetDirectory'

**URL:** <https://root-forum.cern.ch/t/attributeerror-tobject-object-has-no-attribute-setdirectory/51052>\
**Category:** Newbie\
**Created:** [August 3, 2022, 9:19am UTC](https://root-forum.cern.ch/t/attributeerror-tobject-object-has-no-attribute-setdirectory/51052 "2022-08-03T09:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taylor\_Carnahan1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/taylor_carnahan1/32/24336_2.png) [@Taylor\_Carnahan1](https://root-forum.cern.ch/u/Taylor_Carnahan1)\
**Post date:** [August 3, 2022, 9:19am UTC](https://root-forum.cern.ch/t/attributeerror-tobject-object-has-no-attribute-setdirectory/51052/1 "2022-08-03T09:19:49Z")

</div>

Dear experts, I have a python script that is attempting to create Data cards from a hadded root file, but when I attempt to access SetDirectory for the root file, my error occurs. My code portion that is relevant is:

```auto
 self._outFile = ROOT.TFile.Open(outputDirDatacard + "/" + cutName + "/" + variableName + "/shapes/histos_" + tagNameToAppearInDatacard + ".root", 'recreate')

[...]
 histoUp.SetDirectory(self._outFile)
 histoDown.SetDirectory(self._outFile)

```

And, when I open my input hadded root file, I see:

```auto
TFile** rootFile/plots_ggH2018_v7_11_11.root	
 TFile* rootFile/plots_ggH2018_v7_11_11.root	
  KEY: TDirectoryFile	test;1	test

```

I suspect I’m trying to point it to the wrong thing. Any suggestions would be really appreciated! I am using ROOT 6.14/09 within the LXPlus cluster.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [August 3, 2022, 8:30pm UTC](https://root-forum.cern.ch/t/attributeerror-tobject-object-has-no-attribute-setdirectory/51052/2 "2022-08-03T20:30:56Z")

</div>

Hello,

That error indicates that you tried to get a histogram from a ROOT file in Python, but that operation did not succeed and what you got back is a null pointer (to a TObject), and then you try to invoke SetDirectory on it. Can you print `histoUp` and `histoDown` to verify they actually point to something?

---

<div class="post-metadata">

**Author:** ![Taylor\_Carnahan1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/taylor_carnahan1/32/24336_2.png) [@Taylor\_Carnahan1](https://root-forum.cern.ch/u/Taylor_Carnahan1)\
**Post date:** [August 4, 2022, 10:52am UTC](https://root-forum.cern.ch/t/attributeerror-tobject-object-has-no-attribute-setdirectory/51052/3 "2022-08-04T10:52:29Z")

</div>

Hi, etejedor!

Thank you for your response! I ended up revamping an input file that was making some of my histograms come back unfilled. So, the error was actually legitimately useful yesterday (who would’ve thought, right?).

Thank you for your time!
