【问题标题】:What is the invalid syntax error in this def?这个def中的无效语法错误是什么?
【发布时间】:2020-02-13 08:58:14
【问题描述】:

我正在尝试使用用python编写的this Anki add-on

但是,在 Anki 2.1 启动时,返回错误。

任何人都可以快速查看链接中的短代码并发现错误吗?可能是和最近更新的python不兼容?

# Anki 2.0 addon
# Author EJS 
# https://eshapard.github.io/
#
# Sets the learning steps sequence of each deck options group.
from anki.hooks import addHook
from aqt import mw
#from aqt.utils import showInfo
#import time

ignoreList = ['Default', 'OnHold', 'Parent Category'] #Deck options groups to ignore

# run this on profile load
def updateLearningSteps():
   #find all deck option groups
   dconf = mw.col.decks.dconf
   #cycle through them one by one
   for k in dconf:
       if dconf[k]["name"] not in ignoreList:
           #showInfo(dconf[k]["name"])
           ease = dconf[k]["new"]["initialFactor"]/1000.0
           #create learning steps
           tempList = [15]
           for i in range(10):
               l = int(1440*ease**i)
               if l < 28800:
                   tempList.append(l)
               else:
                   gradInts = [(l/1440),(l/1440)]
                   break
           #showInfo(str(tempList))
           #showInfo(str(gradInts))
           mw.col.decks.dconf[k]["new"]["delays"] = tempList
           mw.col.decks.dconf[k]["new"]["ints"] = gradInts
           mw.col.decks.save(mw.col.decks.dconf[k])
   mw.res
et()

# add hook to 'profileLoaded'
addHook("profileLoaded", updateLearningSteps)

这是错误:https://user-images.githubusercontent.com/52420923/66923073-ba2df980-f017-11e9-8b66-c8799db29850.png

【问题讨论】:

    标签: python syntax syntax-error


    【解决方案1】:

    您发布的代码与错误不符。错误有def updateLearningSteps(),行尾没有冒号。这确实是语法错误。

    【讨论】:

    • 哇,确实。我以某种方式错误地复制了代码。
    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多