import random as rd
numberRandomizer = 0
def addNumRandomizer(numArray):
numberRandomizer = rd.randint(50, 100)
for x in numArray:
y = numArray[x] + numberRandomizer
numArray[x] = y
print(numArray)
IndexError: list index out of range
我该如何解决?
答案 0 :(得分:3)
问题出在第7行data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))
,请仔细查看正在发生的事情。
例如,如果您有library(shiny)
library(reticulate)
library(writexl)
#reticulate::source_python("function.py")
#data_xi <- run_xi(26)
if (interactive()) {
ui <-fluidPage(
downloadButton("downloadData", "Download Metrics Reports")
)
#data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21)) # uncomment here, code will working
reticulate::source_python("function.py") # not working when try to use python function by reticulate
data_xi <- run_xi(26)# not working when try to use python function by reticulate
server <- function(input,output){
output$downloadData <- downloadHandler(
filename = function(){
paste(Sys.time(), 'site_mtx.xlsx')
},
content = function(file){
write_xlsx(data_xi, file)
}
)
}
shinyApp(ui, server)}
,则您的y = numArray[x]
将使用该数组的值,并且将其中包含元素的长度为3的同一数组编入索引。这样您将拥有类似numArray = [1, 2, 10]
的信息:x
时,显然这是不可行的,因为您所在的域没有numArray[10]
元素,而只有x = 10
。 / p>
可能的解决方法是:
10th
或更容易地:
3