简体   繁体   English

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

[英]name 'net_input' is not defined even though it is in global

I declared net_input as a global variable but still I am getting NameError: name 'net_input' is not defined 我将net_input声明为全局变量,但仍然出现NameError: name 'net_input' is not defined

global net_input

noise = net_input.detach().clone()

Error line is: 错误行是:

net_input_saved = net_input.detach().clone()

Error 错误

NameError: name 'net_input' is not defined NameError:未定义名称“ net_input”

First you need to define variable and then make it global to use in entire program. 首先,您需要定义变量,然后使其成为全局变量以在整个程序中使用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM