小编Gab*_*eed的帖子

类型错误:“'types.GenericAlias'对象不可迭代”

我正在做的一个项目是将文本转换为数字。(例如,“hello world”将转换为“8 5 12 12 15 27 23 15 18 12 4”)。

在我的代码的第 10 行中,for 循环导致以下错误消息:

Traceback (most recent call last):
  File "C:\Users\gabri\PycharmProjects\padding\main.py", line 15, in <module>
    converter(plaintext)
  File "C:\Users\gabri\PycharmProjects\padding\main.py", line 10, in converter
    for n in plaintext:
TypeError: 'types.GenericAlias' object is not iterable

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

alphabet = ("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')


def getplaintext():
    global plaintext
    plaintext = list[input("Enter plaintext:.....")]
    print(plaintext)

def converter(plaintext):
    for n in plaintext:
        print(n)


getplaintext()
converter(plaintext)
Run Code Online (Sandbox Code Playgroud)

有谁知道是什么导致了这个错误?

python typeerror

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×1

typeerror ×1