Is it possible to use Python code and libraries in Racket? I installed PyonR ( https://github.com/pedropramos/PyonR ) in DrRacket, so I can select "#lang python" and run the Python code. But how can I combine Racket and Python language codes for my application?
There is also a limited translation of Python into Lisp at https://github.com/nurv/pnil . Is there something similar for Racket?
Edit: As recommended in the comments, I tried to follow. This python code in the "pysamples.rkt" file works well in DrRacket:
#lang python def greet(name): print 'Hello', name greet('Alfred')
Output:
Hello Alfred
I tried using the above definition in Racket code, but that didn't work. Below is the Racket code:
#lang racket ; (require python/config) (enable-cpyimport!) ; ran this once; worked. (#%require "pysamples.rkt") (greet "Racket_code")
Error:
greet: unbound identifier in module in: greet
PyonR - Python Racket, . , Python, Python Python, Python C. , ( , - - , ).
, X ( X Python), "" X, Racket , Racket. , , : "R-to-X", Racket , X , "X-to-R", Racket .
, , , .
readme python 2.7, cpyimport. :
cpyimport
#lang python cpyimport numpy as np from "racket" import time def add_arrays(n): result = np.zeros((100,100)) for i in range(n): result += np.random.randint(0, 100000, (100,100)) return result print time(add_arrays(10000))
, python, , #lang python . .
#lang python
The previous answers and comments dealt with difficulties with some Python libraries, but if you are just interested in using a function from a pure Python file in the Racket module, try something like this:
In the file "greetings.py":
#lang python def greet(name): print 'Hello', name
In Racket:
#lang racket (require python) (py-import "greetings" as python-module) (py-method-call python-module "greet" "Racket")
Source: https://habr.com/ru/post/1652691/More articles:Changing the background image applies to each menu item only by scrolling - javascriptPandas dataframe: ValueError: num should be 1 <= num <= 0, not 1 - pythonHow to set prefix to bash verbose mode - bashЧто такое "виртуальный кусок" для виртуальной функции, которая наследуется от виртуального базового класса? - c++julia iteration: start, then, side effects - julia-langSetting up text tensor summation: what is a workspace file? - tensorflowHow to check if a particular row has a validation error for checking multiple rows in Spring using BindingResult - springhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1652694/can-i-now-use-a-jit-for-an-ios-application-that-is-to-be-distributed-through-the-store&usg=ALkJrhhDk9xbJrqX83evZEDuVko8OHbcowAkka.Net and cache consistency - multithreadingЛучший способ производительности, чтобы проверить, изменилось ли contentState в DraftJS, или просто editorState - javascriptAll Articles