【问题标题】:Global name 'debug' not defined全局名称“调试”未定义
【发布时间】:2023-03-05 02:42:01
【问题描述】:

我正在尝试编写一个对 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'。 我以为调试是内置在这里的,为什么不定义呢?如果有帮助,我将在此脚本中使用 ActivePython。

【问题讨论】:

    标签: python python-2.7 activepython


    【解决方案1】:

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

    【讨论】:

    • 所以一开始我会输入global debug?
    • 不,只是 debug=Truedebug=False 视情况而定。 global 用于修改函数内部的全局变量。
    • 所以,debug = True 然后转到下一个未定义的变量 opends。我认为我从中提取此内容的网站给了我一个完整的脚本。
    【解决方案2】:

    内置的全局常量称为__debug__ 而不是debug

    【讨论】:

      【解决方案3】:

      我不使用 ActivePython,这么说。 debug 不是内置的常规 Python。您可以查看python documentation,查看所有内置插件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-04
        • 2015-12-22
        • 2014-04-18
        • 2015-08-08
        • 2011-04-27
        • 2013-09-04
        • 2015-02-26
        • 2016-09-11
        相关资源
        最近更新 更多