python3类型错误:“函数”对象是不可迭代的。

时间:2021-05-12 20:23:16

What change is required in the source code?

在源代码中需要什么更改?


    def Update():
        print('\n')
        print("Update")
        cmd = os.system('xterm -e apt-get update')
        print("Finish update")

    def AptUpdate():
        print('\n')
        print("Update system? {Y/N}")
        print("Y or y")
        print("N or n")
        code = input("Command > ")
        if code == 'y' or code == 'Y':
            for i in Update():
                return Update
            elif code == 'n' or code == 'N': 
                return 
            else: 
                print("Warning!")

    AptUpdate()

    exception:

    Traceback (most recent call last):
      File "pybash.py", line 110, in 
        AptUpdate()
      File "pybash.py", line 102, in AptUpdate
        for i in Update:
    TypeError: 'function' object is not iterable

1 个解决方案

#1


4  

What the traceback error is pointing out is the misuse of for statement:

回溯误差指出的是误用for语句:

for i in Updt():

因为我在Updt():

for in python 3 is as follows: "Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence." (source: python 3.3 documentation, section 4: More control structures Python 3

因为在python 3中是这样的:“python的for语句循环遍历任何序列(列表或字符串)的项,其顺序是它们在序列中出现的顺序。”(来源:python 3.3文档,第4节:更多控制结构python 3

Since a function is neither a list nor a string, you can't use the format:

由于函数既不是列表也不是字符串,所以不能使用以下格式:

for [variable] in [function]():

(变量)的[功能]():

As far as what needs to be fixed, it depends on what those two functions are supposed to accomplish individually.

至于需要解决的问题,则取决于这两个函数各自应该完成什么。

#1


4  

What the traceback error is pointing out is the misuse of for statement:

回溯误差指出的是误用for语句:

for i in Updt():

因为我在Updt():

for in python 3 is as follows: "Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence." (source: python 3.3 documentation, section 4: More control structures Python 3

因为在python 3中是这样的:“python的for语句循环遍历任何序列(列表或字符串)的项,其顺序是它们在序列中出现的顺序。”(来源:python 3.3文档,第4节:更多控制结构python 3

Since a function is neither a list nor a string, you can't use the format:

由于函数既不是列表也不是字符串,所以不能使用以下格式:

for [variable] in [function]():

(变量)的[功能]():

As far as what needs to be fixed, it depends on what those two functions are supposed to accomplish individually.

至于需要解决的问题,则取决于这两个函数各自应该完成什么。