Giter VIP home page Giter VIP logo

Comments (2)

newville avatar newville commented on May 31, 2024

@colmshell I'm glad it helps!

I also have a need to display these user defined formulae. It would be pretty great if this package could help with that by exposing the AST or something. I'm currently using "formulas", but I'm not a great fan of this package.

Don't you already have the user's expression that is sent to the interpreter?

For completeness, you can use the parse method to get back the AST, so that you could do something like

 >>> from asteval import Interpreter 
 >>> import ast
 >>> aeval = Interpreter()
 >>> ast.dump(aeval.parse('sin(x/3)')
"Module(body=[Expr(value=Call(func=Name(id='sin', ctx=Load()), args=[BinOp(left=Name(id='x', ctx=Load()), op=Div(), right=Constant(value=3, kind=None))], keywords=[]))], type_ignores=[])"

That is the AST represents 'sin(x/3)', but I'm not sure what else you would want to do with it (besides "evaluate it"!) that wasn't also represented by the string 'sin(x/3)'.

from asteval.

colmshell avatar colmshell commented on May 31, 2024

Ah, perfect, thanks. I think this probably does what I need.

I wanted to render the formula I'm parsing using HTML. If I have myfunction(x / y), with a parse tree I can hyperlink myfunction, x and y to explanations for users who view the formula.

from asteval.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.