即使名称'net_input'在全局中也未定义

时间:2019-08-08 04:19:45

标签: 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:名称'net_input'未定义

1 个答案:

答案 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()