一行一行执行def中的代码是跑得通的,订阅并调用自定义函数报错Unrecognized column name是为什么?

attachments-2021-11-zzt7ejxV61a33a0e12426.png自定义函数append_plan似乎没有执行,查了下lastErrMsg信息,说没有candidates2,但是提前是定义过的。请问这里报错的原因是什么

请先 登录 后评论

1 个回答

Yating Xie

DolphinDB函数体内只能引用函数参数和函数内的局部变量,不能使用函数体外定义的变量,可以使用共享表。所以candidates2这个变量要么你作为参数传进去,要么在函数里面定义。

方法1:给append_plan函数增加一个参数,比如filters,调用函数时filters位置填candidates2

def append_plan(csEngine1,msg,filters){
    ...
}

方法2:在函数体内定义candidates2

def append_plan(csEngine1,msg){
    candidates2 = ['300471.SZ', '002939.SZ']
    ...
}
请先 登录 后评论