python是否有一些未定义的变量/调试模式,将输出通知/警告?
PHP允许您修改error_reporting以打开通知警告,这意味着
<?php
echo $foo;
将在第2行上抛出“未定义的变量foo”。
python有类似的东西吗?
我在工作时遇到了一个错误
db.connect
代替
db.connect()
我希望python会抛出一个
未定义的变量连接...
您可以提高错误报告级别或python中的类似级别吗?
最佳答案
Python抱怨未定义的变量,没有对其warning system进行任何调整:
h[1] >>> print x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
在您的情况下,
db.connect
实际上具有一个值,即一个函数对象。因此,您的连接不是不确定的。h[1] >>> def hello(): pass
...
h[1] >>> x = hello
h[1] >>> print x
<function hello at 0x100461c80>
关于python - python- undefined variable ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4009795/