TypeError:“列表”对象不可调用;这是什么意思,我该如何解决?

时间:2020-04-28 06:24:06

标签: python python-3.x

我正在尝试用英语输入一个句子,然后全部用猪拉丁字母返回(跟随课程)。

在temp = strlist(a)行上出现错误。我该如何解决?

我有一个单独的功能,可以将一个单词隐蔽为猪拉丁字母,另一个可以将一个句子转换为单词列表。

paperspace@psynjt4iq:~$ pip3 show tensorflow
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of  pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Name: tensorflow
Version: 2.0.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /home/paperspace/.local/lib/python3.7/site-packages
Requires: google-pasta, protobuf, opt-einsum, keras-preprocessing, keras-applications, six, numpy, grpcio, wheel, astor, tens

1 个答案:

答案 0 :(得分:-1)

您好,这里发生错误,因为您调用的是错误的函数。 strlist 是列表,它是列表的单词,您已将该列表发送到 pl()函数中,因此将其删除。

def pl(word):
    if word[0] in 'aeiou':
        word = word + "ay"
        return word
    else:
        word = word[1:] + word[0] + "ay"
        return word

def linetopiglatin(string):
    strlist = string.split()
    for a in strlist:
        #temp = strlist(a)
        temp = pl(a)
        strlist[0] = temp
        return strlist