# Merge\_metaphlan\_tables.py UnboundLocalError

**URL:** https://forum.biobakery.org/t/merge-metaphlan-tables-py-unboundlocalerror/762
**Category:** MetaPhlAn
**Created:** [July 23, 2020, 2:41am UTC](https://forum.biobakery.org/t/merge-metaphlan-tables-py-unboundlocalerror/762 "2020-07-23T02:41:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aimirza](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aimirza/32/499_2.png) [@aimirza](https://forum.biobakery.org/u/aimirza)
#### Post date: [July 23, 2020, 2:41am UTC](https://forum.biobakery.org/t/merge-metaphlan-tables-py-unboundlocalerror/762/1 "2020-07-23T02:41:45Z")

</div>

There is an error when running `merge_metaphlan_tables.py *.rel_ab_w_read_stats.clade_profiles.txt -o merged.rel_ab_w_read_stats.clade_profiles.txt`. Same error whether I use `-o` or `>`. Output files are in `rel_ab_w_read_stats` format. I recently installed metaphlan via conda biobakery

```
Traceback (most recent call last):
  File "/home/amirza/.conda/envs/biobakery3/bin/merge_metaphlan_tables.py", line 10, in <module>
    sys.exit(main())
  File "/home/amirza/.conda/envs/biobakery3/lib/python3.7/site-packages/metaphlan/utils/merge_metaphlan_tables.py", line 81, in main
    merge(args.aistms, fout)
  File "/home/amirza/.conda/envs/biobakery3/lib/python3.7/site-packages/metaphlan/utils/merge_metaphlan_tables.py", line 46, in merge
    names = names,
UnboundLocalError: local variable 'names' referenced before assignment
```

---

<div class="post-metadata">

### Author: ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)
#### Post date: [July 23, 2020, 8:57am UTC](https://forum.biobakery.org/t/merge-metaphlan-tables-py-unboundlocalerror/762/2 "2020-07-23T08:57:17Z")

</div>

Can you replace your `merge_metaphlan_tables.py` from the one present in the repository?  
Another user reported the same problem [here](https://github.com/biobakery/MetaPhlAn/issues/113), I posted a solution a couple of weeks ago.

---

<div class="post-metadata">

### Author: ![elvisfreb](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@elvisfreb](https://forum.biobakery.org/u/elvisfreb)
#### Post date: [January 3, 2022, 4:38pm UTC](https://forum.biobakery.org/t/merge-metaphlan-tables-py-unboundlocalerror/762/3 "2022-01-03T16:38:04Z")

</div>

> [@aimirza](#):
>
> `UnboundLocalError: local variable 'names' referenced before assignment`

An UnboundLocalError is raised when a local variable is referenced before it has been assigned. In most cases this will occur when trying to modify a local variable before it is actually assigned within the local scope. Python doesn’t have variable declarations, so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local.

Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they’re declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can’t modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. However, to modify a [global variable](http://net-informations.com/python/iq/global.htm) inside a function, you must use the global keyword.
