# Using python to access a branch called "E.id"

**URL:** <https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431>\
**Category:** Newbie\
**Tags:** python\
**Created:** [January 18, 2022, 11:21am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431 "2022-01-18T11:21:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [January 18, 2022, 11:21am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/1 "2022-01-18T11:21:09Z")

</div>

Hi there!

I have a ROOT file (let it be named “file.root”), which contains a TTree called “Event”. This TTree contains a leaf called “E.id”.

I want to access the information in E.id, but when I do the script:

import ROOT

f = ROOT.TFile(“file.root”)  
tree=f.Get(“Event”)

for it in tree:  
print (it.E.id)

It says that ‘TTree’ object has no attribute ‘E’. This is due to the dot in E.id, but the file.root is not mine and I can not change the branches names.

Do you know how can I manage to read the data in the E.id leaf?

Thanks in advance!

---

<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:** [January 18, 2022, 11:27am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/2 "2022-01-18T11:27:16Z")

</div>

Yes a “.” in a tree variable name is not a good practice.  
Can you ask the author of this tree how he/she access this “dotted” variable ?  
Otherwise @pcanal might have an idea.

---

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [January 18, 2022, 4:46pm UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/3 "2022-01-18T16:46:26Z")

</div>

This seems to be the best option. I will try to ask him!

Thanks for your answer!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 18, 2022, 6:15pm UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/4 "2022-01-18T18:15:10Z")

</div>

Just to make sure, attach the output of: `tree.Print()`

---

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [January 19, 2022, 9:06am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/5 "2022-01-19T09:06:50Z")

</div>

![cap](https://root-forum.cern.ch/uploads/default/original/3X/2/b/2b5a3ce2ad96021ba10a219eb1073ec5b41f39b9.png)

In fact the branch is called E.run\_id, but it’s the same problem.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 19, 2022, 9:15am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/6 "2022-01-19T09:15:43Z")

</div>

Indeed, in the case of this tree, you should ask the author to change “`E.`” into, e.g., “`E_`”.

---

<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:** [January 19, 2022, 9:34am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/7 "2022-01-19T09:34:55Z")

</div>

Exactly …  
And may be also ask the author what is the purpose of a variable you cannot access ?  
Has he ever tried to access it himself ? It looks like a bug, a design mistake…

And it is not only `E.run_id` but also `E.frame_index` and `E.trigger_counter`

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 19, 2022, 9:41am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/8 "2022-01-19T09:41:23Z")

</div>

@couet I guess, you can access these variables, if you use the standard [`TTree::SetBranchAddress`](https://root.cern/doc/master/classTTree.html#a39b867210e4a77ef44917fd5e7898a1d) way.

---

<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:** [January 19, 2022, 10:11am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/9 "2022-01-19T10:11:04Z")

</div>

> [@Miguel](#):
>
> for it in tree:  
> print (it.E.id)

You can also try

```auto
for it in tree:
    print(getattr(it, "E.id"))

```

---

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [January 20, 2022, 8:49am UTC](https://root-forum.cern.ch/t/using-python-to-access-a-branch-called-e-id/48431/10 "2022-01-20T08:49:43Z")

</div>

That worked perfectly, thanks a lot!
