python - 名称 'net_input' 未定义,即使它在全局中

标签 python global

我将 net_input 声明为全局变量,但仍然收到 NameError: name 'net_input' is not Defined

global net_input

noise = net_input.detach().clone()

错误行是:

net_input_saved = net_input.detach().clone()

错误

NameError: name 'net_input' is not defined

最佳答案

首先您需要定义变量,然后将其设置为全局变量以在整个程序中使用。

net_input = "some object"   # assume this is an object and defined somewhere else in your program

global net_input            # make sure that net_input is defined prior 

noise = net_input.detach().clone()

关于python - 名称 'net_input' 未定义,即使它在全局中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57405150/

相关文章:

通过 Globals API 的 Java 连接导致 StackOverflowError

python - 选择要下载文件的哪一部分

python - 无法解决 pyenv zlib 错误

python套接字和套接字服务器

python - 如何在列表中比较python中的字符串?

actionscript-3 - globals 或 'evil' singletons 有什么意义吗

python - 无法弄清楚如何调试这个: ValueError: invalid literal for int() with base 10: '

function - 如何在qml中创建全局函数

javascript - context.RewritePath 和 jquery ajax 不调用 webmethod

c++ - 每次调用 C++ 函数时,如何防止变量被重新初始化?