【问题标题】:Too many parameters error, but called with correct amount参数太多错误,但以正确的数量调用
【发布时间】:2014-07-13 19:34:56
【问题描述】:

有一个关于这个错误的问题:

TypeError: rot13() takes exactly 1 argument (2 given)

在此代码上发生的情况:

def get(self): <-- called on every get request
    ch = self.rot13("abc")

def rot13(input): <-- fairly untested rot 13 ;)
    alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
         'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    escaped = escape(input)
    ciphered = ""
    for char in escaped:
        originalIndex = alpha.index(char)
        newIndex = (originalIndex + 13) % 26
        ciphered = chipered + alpha[newIndex]

不知道为什么会出现这个错误。我只是在那里处理一个参数。

【问题讨论】:

    标签: python-2.7 webapp2


    【解决方案1】:

    您似乎错过了这个:

    def rot13(self, input):
    

    …那是因为rot13()似乎是一个类中的方法,而不是一个独立的函数,所以它需要接收self

    【讨论】:

    • 哦是的 :) 初学者的错误。这是 python 还是 webapp2 特定的?
    • 这是 Python 特有的 :)
    • 谢谢。 10 分钟结束后将接受。 (来自其他语言,这真的很奇怪)
    猜你喜欢
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多