Accept a function for the `nameattr` parameter in the `print_tree` function. I'd be happy to make a pull request!