UnboundLocalError: local variable ‘xxx‘ referenced before assignment
原因
在Python函数中调用了某个和全局变量同名的局部变量,导致编译器不知道此时使用的是全局变量还是局部变量
a = 3
def func():
a+=3 func()
UnboundLocalError:....
解决方法
在函数中,用global声明该变量为全局变量:
a = 3
def func():
global a
a+=3 func()
UnboundLocalError: local variable ‘xxx‘ referenced before assignment的更多相关文章
- python:UnboundLocalError: local variable 'xxx' referenced before assignment
近来一直都在学习python语言,偶然在伯乐在线看到2017年京东C/C++的面试题.就打算用python+ST3 IDE顺便敲下面试题代码. 原题 C语言: #include <stdio.h ...
- python: local variable 'xxx' referenced before assignment
问题发现 xxx = 23 def PrintFileName(strFileName): if xxx == 23: print strFileName xxx = 24 PrintFileName ...
- Python问题:UnboundLocalError: local variable 'xxx' referenced before assignment
参考链接: http://blog.csdn.net/onlyanyz/article/details/45009697 https://www.cnblogs.com/fendou-999/p/38 ...
- local variable 'xxx' referenced before assignment
这个问题很囧,在外面定义了一个变量 xxx ,然后在python的一个函数或类里面引用这个变量,并改变它的值,结果报错local variable 'xxx' referenced before as ...
- RDO Stack Exception: UnboundLocalError: local variable 'logFile' referenced before assignment
Issue: When you install RDO stack on CentOS, you may encounter following error. Error: [root@localho ...
- 洗礼灵魂,修炼python(23)--自定义函数(4)—闭包进阶问题—>报错UnboundLocalError: local variable 'x' referenced before assignment
闭包(lexical closure) 什么是闭包前面已经说过了,但是由于遗留问题,所以单独作为一个章节详解讲解下 不多说,看例子: def funx(x): def funy(y): return ...
- [合集]解决Python报错:local variable 'xxx' referenced before assignment
a = 1 def use(): print(a) #输出1 引用不会报错 a = 1 def use(): a = 3 print(a) #输出 3 重新赋值也不会报错. 局部变量会优先在函数内部去 ...
- local variable 'xxx' referenced before assignment(犯过同样的错)
这个问题很囧,在外面定义了一个变量 xxx ,然后在Python的一个函数里面引用这个变量,并改变它的值,结果报错local variable 'xxx' referenced before assi ...
- _markupbase.py if not match: UnboundLocalError: local variable 'match' referenced before assignment,分析Python 库 html.parser 中存在的一个解析BUG
BUG触发时的完整报错内容(本地无关路径用已经用 **** 隐去): **************\lib\site-packages\bs4\builder\_htmlparser.py:78: U ...
随机推荐
- logrotate 日志切割
logrotate是一个日志文件管理工具.用于分割日志文件,删除旧的日志文件,并创建新的日志文件,起到"转储"作用. 配置文件 Linux系统默认安装logrotate工具,它默认 ...
- Lesson3——Pandas Series结构
1 什么是Series结构? Series 结构,也称 Series 序列,是 Pandas 常用的数据结构之一,它是一种类似于一维数组的结构,由一组数据值(value)和一组标签组成,其中标签与数据 ...
- autorelease注意事项
1.autorelease使用注意 并不是放到自动释放池代码中,都会自动加入到自动释放池 @autoreleasepool { // 因为没有调用 autorelease 方法,所以对象没有加入到自动 ...
- spring 注解注入bean
通过注解方式注入bean,需要在配置类下注入bean 第一步,配置扫描文件夹 首先要在spring.xml中配置需要扫描的配置类 <context:componenet-scan base-pa ...
- java创建自定义类的对象数组
1 public class Student{ 2 static int number = 0; // 静态变量的访问可以不用创建类的实例就可就可使用< 类名.属性 >的方法访问 3 ...
- js实现网页中英文翻译
1,html 2,metrics.js 3,需要 http://www.microsoftTranslator.com/ajax/v3/WidgetV3.ashx?siteData=ueOIGRSKk ...
- Mac版jdk1.6
java sdk 1.6 for mac 在苹果官网下载 https://support.apple.com/kb/DL1572?locale=zh_CN
- Ansible 自动化运维——剧本(playbook)
Ansible 自动化运维--剧本(playbook) 1.playbook介绍: playbook是ansible用于配置,部署,和管理被控节点的剧本.通过playbook的详细描述,执行其中的ta ...
- 使用haproxy的ACL实现基于文件后缀名的动静分离
一.环境准备 二.实现proxy [root@localhost ~]# yum -y install haproxy #创建子配置 [root@localhost ~]# mkdir /etc/ha ...
- linux_6
1.编写脚本实现登陆远程主机.(使用expect和shell脚本两种形式). #使用expect远程登录 [root@centos8 ~]#dnf -y install expect [root@ce ...