Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider having option to label sympy expressions with their python name #37

Open
gutow opened this issue Aug 13, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@gutow
Copy link
Owner

gutow commented Aug 13, 2024

This would require adding another option to output formatting (e.g. sympy_expr_labels). When requested sympy expressions would be labeled with the python name for the expressions just as equations are by default.

The operation to extract equation labels could be used more generically and not be a part of the expression object. Rough code to get the necessary string for the label would be:

def _get_eqn_name(expr):
    """
    Tries to find the python string name that refers to a sympy object. In
    IPython environments (IPython, Jupyter, etc...) looks in the user_ns.
    If not in an IPython environment looks in __main__.
    :return: string value if found or empty string.
    """
    import __main__ as shell
    for k in dir(shell):
        item = getattr(shell, k)
        if isinstance(item, Basic):
            if item == expr and not k.startswith('_'):
                return k
    return ''

This could also take over for the similar function currently embedded in the equation type, further removing output tweaking from sympy proper.

@gutow gutow added the enhancement New feature or request label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant