1、UnboundLocalError: local variable 'xxx' referenced before assignment
参考链接:
http://blog.csdn.net/onlyanyz/article/details/45009697
https://www.cnblogs.com/fendou-999/p/3822028.html
2、IndentationError: expected an indented block
缩进错误
3、PyCharm下解决Unresolved Reference问题
https://blog.csdn.net/haiyanggeng/article/details/79215819
4、<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>
在HTMLTestRunner.py的631行,
print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)
或者
print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))
修改成
sys.stderr.write('\nTime Elapsed: %s\n' % (self.stopTime - self.startTime))
5、warning:statement has no effect:申明无效
检查是否给全局变量赋值了。
6、shadows name 'xxx' from outer scope
当你在外部有个相同名称的变量在方法内部被重新指定了新的值,也就是说你在外部的相同名称的变量压根就没有任何作用。
python的变量作用域:
模块对应global,
最内层为local,
外层为nonlocal
变量查找顺序:内层作用域->外层->全局->builtin
只有class、def和lamda会改变作用域
读取变量的时候,如果local没有,查找nonlocal,然后global
写变量的时候,如果没有指明nonlocal/global, 就是在局部作用域定义一个新的变量
Python 五个知识点搞定作用域:http://python.jobbole.com/86465/
7、unexpected argument
函数中添加一个参数试试:params=None
8、‘xxx’takes 0 positional arguments but 1 was given
这个函数xxx不需要参数,但是函数却被传递了一个参数
9、python positional argument follows keyword argument
当参数的位置不正确时,就会报上面的错误;
关键字参数
必须跟随在位置参数
后面! 因为python函数
在解析参数时, 是按照顺序来的, 位置参数
是必须先满足, 才能考虑其他可变参数.
10、ValueError: no such test method in <class '__main__.TestInterfaceRun'>: test_01
11、TypeError: a bytes-like object is required, not 'str'
在字符串前加b
https://www.cnblogs.com/dpf-learn/p/8028121.html
12、UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 259: invalid continuation byte
try:
html = html.decode('UTF-8') # html是bytes类型的字符串
except UnicodeDecodeError as reason:
print(reason)
html = html.decode('GBK')
except UnicodeDecodeError as reason:
print(reason)
13、同级目录导入问题
14、pycharm无法import已安装模块