我将 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/