开发者

What is wrong with this module?

I have triple checked the syntax on this python module statement, and it is NOT working...

correct = 0
ahtriggercount = 0

def IsCorrect():
    #Increase correct count.
    correct = correct + 1
    #Lower autohelp trigger count.
    if ahtriggercount > 0:
      开发者_开发知识库  ahtriggercount = ahtriggercount - 1

The general "syntax error" (no further information is being given by the IDE) is being thrown at...

if ahtriggercount > 0:

What is wrong? Why can't we access the ahtriggercount variable?


You need to tell python that you're accessing a global variable. Like this:

correct = 0
ahtriggercount = 0

def IsCorrect():
    global correct, ahtriggercount
    #Increase correct count.
    correct = correct + 1
    #Lower autohelp trigger count.
    if ahtriggercount > 0:
        ahtriggercount = ahtriggercount - 1

Global variables are read-only by default unless you use the global declaration.

You also had a whitespace issue. There were some strange spaces on one of the lines. When I deleted the spaces and added them again, I stopped getting IndentationError.


You need to declare ahtriggercount and correct as global because you are modifying their value.

def IsCorrect():
    global ahtriggercount, correct
    #Increase correct count.
    correct = correct + 1
    #Lower autohelp trigger count.
    if ahtriggercount > 0:
        ahtriggercount = ahtriggercount - 1


Without knowing the error message we can only guess. However, your snippet seems to be syntactically correct. Maybe you mixed up spaces and tabs or forgat a space or tab in one line? Right indentation is crucial in Python.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜