我是靠谱客的博主 善良音响,最近开发中收集的这篇文章主要介绍python中对象不可迭代_python3 TypeError:'function'对象不可迭代,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

解决方案

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

for i in 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

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.

最后

以上就是善良音响为你收集整理的python中对象不可迭代_python3 TypeError:'function'对象不可迭代的全部内容,希望文章能够帮你解决python中对象不可迭代_python3 TypeError:'function'对象不可迭代所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部