python - 全局名称 'debug' 未定义

标签 python python-2.7 activepython

我正在尝试编写一个对 AD 进行身份验证的脚本。这是我的问题:

import sys
sys.stdout = open('output.csv', 'w')
def ad_dict(ldapobj,attr_dict={},recurse=0,auth=1,filter=()):
  if ldapobj.find(',')==-1: ldapobj='cn='+ldapobj+','+Ad.ldap_main_loc
  if auth: #setup authenticated connections
   if debug: print 'auth'

当我运行它时,它会显示“全局名称‘debug’未定义。 我以为debug是内置的,为什么不定义呢?如果有帮助,我将使用 ActivePython 来编写此脚本。

最佳答案

如果您需要此功能,为什么不定义一个名为 debug 的全局变量呢? (或使用logging.debug())

关于python - 全局名称 'debug' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12919646/

相关文章:

使用 Azure Log Analytics 进行 Python 应用程序日志记录

python - 如何在 Jupyter 中将 %%time 值存储在变量中?

python - 我可以将 numpy 数组作为参数传递给函数,就像变量一样吗?

python - 如何修复找不到 sdist pip-*.tar.gz

python - Pygame 显示没有响应

python 将字典数组映射到字典?

python 2.7小写

python - 如何在 ActivePython 2.7 的 OSX 10.5 32 位上安装 OpenCV 2.2?

python - ActivePython 和 MySQLdb

python - 处理 NaN 进行距离计算时出现问题?