Giter Site home page Giter Site logo

Comments (3)

jhanna-kx avatar jhanna-kx commented on July 26, 2024 2

To do this I think you'll need to use .p.e. not .p.eval`

.p.eval and p.e (used when prefixing code with p)) run the PyRun_String C API function internally, the difference is that .p.e run's it with Py_file_input allowing multiple expressions with side effects but not returning any value and .p.eval uses Py_eval_input which returns a value but is not allowed to have side effects.

.p.e is analogous to python's exec
.p.eval/pyeval are analogous to python eval

>>> eval('x=2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    x=2
     ^
SyntaxError: invalid syntax
>>> y=exec('z=10')
>>> print(y,z)
None 10

There's a longer explanation at the link below here https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile-in-python

from embedpy.

clovetea avatar clovetea commented on July 26, 2024

Great explanation, thank you. It would be helpful if the difference between .p.e and .p.eval was mentioned in the readme.

from embedpy.

jhanna-kx avatar jhanna-kx commented on July 26, 2024

Thanks, we'll add a note to the README for this

from embedpy.

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.