我将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:名称'net_input'未定义
答案 0 :(得分:0)
首先,您需要定义变量,然后使其成为全局变量以在整个程序中使用。
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()