簡體   English   中英

無法遍歷 python 中的循環

[英]unable to iterate through loop in python

我有一個 sql 查詢,它基本上檢索硬幣名稱並為每個硬幣提交訂單。 然而,它只提交了一個硬幣的訂單並且無法通過 rest 循環,不知道為什么會這樣。

import sys

**
import pandas as pd


postgreSQL_select_Query = "SELECT base,quote FROM instrument_static where exchange='ftx'"

cursor.execute(postgreSQL_select_Query)
row=([y for y in cursor.fetchall()])

for i in row:
   base=i[0]
   quote=i[1]
   portfolioItems = [
       {
           'exchange': 'ftx',
           'base': base,
           'quote': quote,
           'amount': 0.01,
       },

   ]


   def init():

       username = us
       password = passwordVal
       initialise(clientId, clientSecret, us, password)


if __name__ == "__main__":
       init()
       result = construct_portfolio_with_params(us, portname, portfolioItems)
       print(result)

您需要在循環之前初始化portfolioItems ,然后您可以添加到它。 嘗試替換這段代碼:

...
row=([y for y in cursor.fetchall()])

portfolioItems = []

for i in row:
   base=i[0]
   quote=i[1]
   portfolioItems.append(
       {
           'exchange': 'ftx',
           'base': base,
           'quote': quote,
           'amount': 0.01,
       }

   )
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM