Python 将变量从列表循环中加引号?
我尝试使用以下代码循环浏览硬币列表:Python 将变量从列表循环中加引号?,python,list,variables,Python,List,Variables,我尝试使用以下代码循环浏览硬币列表: coin = ["BTC", "NEO", "ETH"] for item in coin: try: term = urllib.parse.quote("'" + coin + "-BTC'") depth = client.get_order_book(term, limit=50) except (KucoinAPIException, KucoinRequestException, KucoinR
coin = ["BTC", "NEO", "ETH"]
for item in coin:
try:
term = urllib.parse.quote("'" + coin + "-BTC'")
depth = client.get_order_book(term, limit=50)
except (KucoinAPIException, KucoinRequestException, KucoinResolutionException) as e:
print(e)
pass
我收到了错误信息:
TypeError: must be str, not list
实现这一目标最有效的方法是什么?我必须把我的名单分开吗?谢谢大家! 使用for循环来实现这一点可能更容易、更高效/更具吸引力:
coin = ["BTC", "NEO", "ETH"]
for i in coin:
term = urllib.parse.quote("'" + i + "-BTC'")
depth = client.get_order_book(term, limit=50)
欢迎来到StackOverflow。请阅读并遵循帮助文档中的发布指南。适用于这里。在您发布MCVE代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中,并重现您描述的问题。您的代码不会按发布的方式运行,并且您未能提供完整的错误消息。您的问题是…来自列表循环。好吧,这正是你在这里需要而且还没有写的东西:列表上的循环。我粘贴了更多的代码,我想这是不可能的?如果是这样,我会删除它。。。