ete
ete copied to clipboard
Name attribute does not handle "&" within a string properly when trying to print
I have a file that has customer-specified account names in it. These names will contain the "&" symbol, which creates issues when trying to use print(t). t.children will provide the name, but print(t) seems to have some parsing issues with "&" in a name.
from ete3 import Tree
t = Tree()
t.add_child(name='LIABILITIES & EQUITY')
print(t)
I get the following error:
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ete3\coretype\tree.py in __str__(self)
251 def __str__(self):
252 """ Print tree in newick format. """
--> 253 return self.get_ascii(compact=DEFAULT_COMPACT, \
254 show_internal=DEFAULT_SHOWINTERNAL)
255
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ete3\coretype\tree.py in get_ascii(self, show_internal, compact, attributes)
1500
1501 """
-> 1502 (lines, mid) = self._asciiArt(show_internal=show_internal,
1503 compact=compact, attributes=attributes)
1504 return '\n'+'\n'.join(lines)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ete3\coretype\tree.py in _asciiArt(self, char1, show_internal, compact, attributes)
1470 else:
1471 char2 = '-'
-> 1472 (clines, mid) = c._asciiArt(char2, show_internal, compact, attributes)
1473 mids.append(mid+len(result))
1474 result.extend(clines)
AttributeError: 'str' object has no attribute '_asciiArt'
edit: code block formatting
Hi, I tried the code you demonstrated and seems fine, I wonder if it could be the version issues. Mine is: ete3.1.2 python 3.6.10 & python3.7
In [1]: from ete3 import Tree ...: t = Tree() ...: t.add_child(name='LIABILITIES & EQUITY') ...: print(t)
-- /-LIABILITIES & EQUITY