cuốn sách gpt4 ai đã làm

python - 如何使用 rPython 从 R 向 Python 输入参数?

In lại Tác giả: Walker 123 更新时间:2023-11-28 22:29:52 25 4
mua khóa gpt4 Nike

如何使用包 rPython 从 R 向 Python 输入参数?

下面是一个幼稚的尝试

在 script.py 中:

print message

在 script.R 中:

require(rPython)    
text = "Hello World"
python.load("script.py", message=text)

Error in python.load("script.py", message = text) :
unused argument (message = text)

câu trả lời hay nhất

根据包裹的 docs (第 5-6 页)对于 trọng tải phương pháp:

This function runs Python code contained in a file. Typically, this file would contain functions to be called via python.call or other functions in this package.

因此,在 Python 中没有运行脚本,只有带有返回对象的定义函数:

Python (script.py)

def print_message(msg):
return msg

R (使用加载和调用)

require(rPython)    
text = "Hello World"

python.load("script.py")
python.call("print_message", text)

#[1] "Hello World"

关于python - 如何使用 rPython 从 R 向 Python 输入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42823115/

25 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress