Python对列表中的每个条目都做了什么?
所以我一直在通过python与TrelloAPI交互。 当我得到我的卡片时,它返回(除其他外)这个列表(将其转换为JSON表示漂亮) 我试过了Python对列表中的每个条目都做了什么?,python,list,trello,Python,List,Trello,所以我一直在通过python与TrelloAPI交互。 当我得到我的卡片时,它返回(除其他外)这个列表(将其转换为JSON表示漂亮) 我试过了 for card in x.cards: print "hi" 但这让我犯了这个错误 AttributeError: 'list' object has no attribute 'cards' 我的最终目标是获得每个“name”属性并将其打印到一个txt文件中(我知道如何将内容写入.txt文件) 在最终结果中,将会有更多thn 1卡ofc。我建议您
for card in x.cards:
print "hi"
但这让我犯了这个错误
AttributeError: 'list' object has no attribute 'cards'
我的最终目标是获得每个“name”属性并将其打印到一个txt文件中(我知道如何将内容写入.txt文件)
在最终结果中,将会有更多thn 1卡ofc。我建议您使用py trello API从您的电路板检索数据。从你的牌中获得属性非常容易。见下面的示例:
from trello import TrelloClient
def main():
client = TrelloClient(
api_key=TRELLO_API_KEY,
api_secret=TRELLO_API_SECRET,
token=TRELLO_OAUTH,
token_secret=TRELLO_OAUTH_SECRET
)
boards = client.list_boards()
for b in boards:
print("\n# {}\n\n".format(b.name))
print_board(b)
def print_board(board):
lists = board.list_lists()
for l in lists:
print("\n## {}\n".format(l.name))
print_list(l)
def print_list(lst):
cards = lst.list_cards()
for c in cards:
print("* {}".format(c.name))
if __name__ == '__main__':
main()
有关更多信息,请参阅和
的示例信用卡首先尝试打印
x
本身。它不是您期望的json
。另外,您可能需要使用x['cards']
而不是x.cards
。这对我一点帮助都没有。即使您将x[“cards”]转换为json或不转换为json,x[“cards”]也不会起任何作用。正如我提到的,请先检查您的x
。打印出来。查看其内容并相应地采取行动。
from trello import TrelloClient
def main():
client = TrelloClient(
api_key=TRELLO_API_KEY,
api_secret=TRELLO_API_SECRET,
token=TRELLO_OAUTH,
token_secret=TRELLO_OAUTH_SECRET
)
boards = client.list_boards()
for b in boards:
print("\n# {}\n\n".format(b.name))
print_board(b)
def print_board(board):
lists = board.list_lists()
for l in lists:
print("\n## {}\n".format(l.name))
print_list(l)
def print_list(lst):
cards = lst.list_cards()
for c in cards:
print("* {}".format(c.name))
if __name__ == '__main__':
main()