Title: Add PythonEngine Eval and Exec by yagweb · Pull Request #389 · pythonnet/pythonnet · GitHub
Open Graph Title: Add PythonEngine Eval and Exec by yagweb · Pull Request #389 · pythonnet/pythonnet
X Title: Add PythonEngine Eval and Exec by yagweb · Pull Request #389 · pythonnet/pythonnet
Description: "eval" and "exec" are two of the most frequently used methods when interacting with Python. However, I found there is not "eval" provided currently, this statement var flag = (IntPtr)257; in PythonEngine.RunString method makes this method can only be used as "exec". Two .NET functions equivalent to the Python “evel” and “exec” are implemented by wrapping the PyRun_String function just like the CPython does. PythonEngine.RunString method became internal. All the modifications located in pythonengine.cs. All the places using PythonEngine.RunString are replaced with the new PythonEngine.Exec method. Unit tests are given in the new file "src/embed_tests/pyrunstring.cs", They can also be used as examples. List one of them below. Eval the python expression "sys.attr1 + a + 1" and obtain its value. dynamic sys = Py.Import("sys"); sys.attr1 = 100; PyDict locals = new PyDict(); locals.SetItem("sys", sys); locals.SetItem("a", new PyInt(10)); var b = PythonEngine.Eval("sys.attr1 + a + 1", null, locals.Handle) .AsManagedObject(typeof(Int32)); Console.WriteLine("sys.attr1 + a + 1 = {0}", b); CHANGELOG.md will be updated later.
Open Graph Description: "eval" and "exec" are two of the most frequently used methods when interacting with Python. However, I found there is not "eval" provided currently, this statement var...
X Description: "eval" and "exec" are two of the most frequently used methods when interacting with Python. However, I found there is not "eval" provided curre...
Opengraph URL: https://github.com/pythonnet/pythonnet/pull/389
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5c59e8ea-eb52-9728-81d0-cac1400608e6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9F92:2F50C0:239A015:321FD94:6970F292 |
| html-safe-nonce | a946cd40624128b6eaa2a8cffd53beec99bfc751bf7b44427846f010fee93436 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjkyOjJGNTBDMDoyMzlBMDE1OjMyMUZEOTQ6Njk3MEYyOTIiLCJ2aXNpdG9yX2lkIjoiODU0Mjc1OTYwOTI5MjYxNjMzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e2d1f151413e2fd9b97b70d6e33bf54aad00cfce1028dfeabafbeb20edab8906 |
| hovercard-subject-tag | pull_request:106685396 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/pythonnet/pythonnet/pull/389/files |
| twitter:image | https://avatars.githubusercontent.com/u/13247575?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/13247575?s=400&v=4 |
| og:image:alt | "eval" and "exec" are two of the most frequently used methods when interacting with Python. However, I found there is not "eval" provided currently, this statement var... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b6ca3cb96fa07d8a62b95d681f9dc8fffb49a43f4fea2a5bcac6d8f5107cbf4e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d2448578278810c7bf94faa67651ef5adb1abfde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width