以下代码在我的python ide中工作正常:
counter = 1000
def increment():
global counter
counter += 1
increment()
print(counter)
但是当我复制和粘贴一个pl/python函数中的代码(如下所示)时,它不起作用。
counter = 1000
def increment():
global counter
counter += 1
increment()
plpy.notice(counter)
返回的错误消息为:
ERROR: NameError: name 'counter' is not defined
CONTEXT: Traceback (most recent call last):
PL/Python function "testing", line 9, in <module>
increment()
PL/Python function "testing", line 6, in increment
counter += 1
PL/Python function "testing"