簡體   English   中英

網狀 - 獲取Python結果而不分配變量

[英]Reticulate - Get Python result without assigning to variable

如果可能的話,我想在R中打印python代碼的結果(不分配給變量)。

這有效:

library(reticualte)
py_run_string("print(2)")
2

這有效:

p = py_run_string("x = 2")
p$x
2

我希望這個工作:

py_run_string("2")
2

背景:

我想閱讀完整的python代碼並捕獲輸出,即使沒有使用(打印)。

如果我打開Python3.7 Shell並只執行“2”作為命令,則輸出將為“2”。 這里空無一人。

鏈接到Github請求: https//github.com/rstudio/reticulate/issues/595

我要去跟no嘗試過此之后。

嘗試:

return(
    py_run_string("2")
)

嘗試:

f <- function() {
   return( 
       py_run_string("2")
   )
}

f()

std中似乎沒有任何東西

與:

b <- function() {
   return(2)
}

b()

# Out[]:  2

我猜測它正在訪問python的local()變量。

也:

library(reticulate)

py_run_string("2")
ls()
# Out[1]:   None


a <- 3
ls()
# Out[2]:   'a'

R的局部變量代表py_run_string()輸出

鏈接到Github請求: https//github.com/rstudio/reticulate/issues/595

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM