# Python-CPP Interoperativity: Accessing TTree generated by external macros in python (conda environment)

**URL:** <https://root-forum.cern.ch/t/python-cpp-interoperativity-accessing-ttree-generated-by-external-macros-in-python-conda-environment/51736>\
**Category:** Newbie\
**Tags:** root\
**Created:** [September 28, 2022, 2:26am UTC](https://root-forum.cern.ch/t/python-cpp-interoperativity-accessing-ttree-generated-by-external-macros-in-python-conda-environment/51736 "2022-09-28T02:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NgJunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ngjunkai/32/30046_2.png) [@NgJunKai](https://root-forum.cern.ch/u/NgJunKai)\
**Post date:** [September 28, 2022, 2:26am UTC](https://root-forum.cern.ch/t/python-cpp-interoperativity-accessing-ttree-generated-by-external-macros-in-python-conda-environment/51736/1 "2022-09-28T02:26:55Z")

</div>

I am writting an external macro that looks like this:

```auto
TTree* t2(string fname, int num){
	cout << "file number: "<< num << endl;
	TTree* tree=new TTree(fname.c_str(),"tttname");
	return tree;
}

```

Then in jupyterlab, I run `ROOT.gROOT.ProcessLine('.x ./t2.C("hhh",465)')`  
What I want is that this macro return a `<cppyy.gbl.TTree object at 0x55b9c272f920>` object in python so i can readily access it.  
Instead, the macro return the address (which is a `hex` converted to `int`), this makes the access of the object not straightforward (as i need to get back the object by its address). (see figure)  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/f/b/fbad9a9006f4750b909d65efb2c9935a89e6bf16.png)

Is there any tweak to the macro so that I can do the thing in a more straightforward way ?

* * *

\_ROOT Version: 6.24 (PyROOT via conda)  
\_Platform:Centos7  
\_Compiler: gcc9

* * *

---

<div class="post-metadata">

**Author:** ![NgJunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ngjunkai/32/30046_2.png) [@NgJunKai](https://root-forum.cern.ch/u/NgJunKai)\
**Post date:** [September 28, 2022, 5:06am UTC](https://root-forum.cern.ch/t/python-cpp-interoperativity-accessing-ttree-generated-by-external-macros-in-python-conda-environment/51736/2 "2022-09-28T05:06:24Z")

</div>

Update:  
I found the solution. When I execute the code, it is in ROOT environment, so the adress is returned. For this case, I need to manuall do the binding to python object for the address. (see figure below)

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/4/4/44e94e6351450a33618ef5c490e1afc82eeacf3b.png)

However the external function has already reside in the ROOT environment, with python proxy created by `cppyy`. Therefore, if I invoke the function, the fuction returns the TTree as a python object. (see figure below)

![image](https://root-forum.cern.ch/uploads/default/original/3X/c/3/c314a9d689b901e324e6db2dbbde1c82a6448a15.png)
