|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
From Nim, call Python's eval() functionThis is a powerful stuff. For Python's print(eval("1 + 1")) # 2 print(eval("2 ** 3 - 1")) # 7 Note: ProblemI couldn't call SolutionThere's a solution for the previous problem: create a Python module with a function that calls $ tree . . ├── helper.py └── main.nim
def myeval(code): return eval(code)
import std/os import pkg/nimpy proc main() = let sys = pyImport("sys") discard sys.path.insert(0, getAppDir()) # directory of the running binary let helper = pyImport("helper") result = helper.myeval("2 ** 3 - 1").to(int) echo result # 7 echo result.typeOf # int main() ![]() |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |