Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将变量从列表循环中加引号?_Python_List_Variables - Fatal编程技术网

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代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中,并重现您描述的问题。您的代码不会按发布的方式运行,并且您未能提供完整的错误消息。您的问题是…来自列表循环。好吧,这正是你在这里需要而且还没有写的东西:列表上的循环。我粘贴了更多的代码,我想这是不可能的?如果是这样,我会删除它。。。