# Error using SetDirectory

**URL:** <https://root-forum.cern.ch/t/error-using-setdirectory/38640>\
**Category:** Newbie\
**Created:** [March 31, 2020, 5:25am UTC](https://root-forum.cern.ch/t/error-using-setdirectory/38640 "2020-03-31T05:25:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adecours](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/7feea3/32.png) [@adecours](https://root-forum.cern.ch/u/adecours)\
**Post date:** [March 31, 2020, 5:25am UTC](https://root-forum.cern.ch/t/error-using-setdirectory/38640/1 "2020-03-31T05:25:11Z")

</div>

I’m getting this error when I try to run a python plotting script:

```auto
AttributeError: 'TObject' object has no attribute 'SetDirectory'

```

Here is the part of the script for fetching the histograms / where I’m getting the error:

```auto
fileName1 = "20200311_histos.root"
variable1 = "recpt"
file1 = ROOT.TFile.Open(fileName1,"READ")
h1 = file1.Get(variable1)
h1.SetDirectory(0)
if (file1.IsOpen()):
    file1.Close()

```

and the lines used for fetching python / importing ROOT:

```auto
#!usr/bin/env python
import os
import sys
import numpy as np
import math
from array import array
import ROOT

```

(I installed ROOT with homebrew.)

Does anyone know how to solve this?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 31, 2020, 5:59am UTC](https://root-forum.cern.ch/t/error-using-setdirectory/38640/2 "2020-03-31T05:59:24Z")

</div>

It is true that `TObject` does not have a `SetDirectory` method. It looks like your object `h1` is considered as a `TObject` it should be a `TH1`. (@etejedor ?)

---

<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:** [March 31, 2020, 7:28am UTC](https://root-forum.cern.ch/t/error-using-setdirectory/38640/3 "2020-03-31T07:28:34Z")

</div>

Hi,

I believe the problem is that the histogram is not retrieved correctly from the file, at this line:

```auto
h1 = file1.Get(variable1)

```

Can you double check that “recpt” exists in the file? You can do file1-\>ls().
