當前位置: 首頁>>代碼示例>>Python>>正文


Python DB.fetchall方法代碼示例

本文整理匯總了Python中db.DB.fetchall方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.fetchall方法的具體用法?Python DB.fetchall怎麽用?Python DB.fetchall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在db.DB的用法示例。


在下文中一共展示了DB.fetchall方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: player_standings

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import fetchall [as 別名]
def player_standings():
    """
    Returns a list of the players and their win records, sorted by wins.

    The first entry in the list should be the player in first place, or a player
    tied for first place if there is currently a tie.

    Returns:
      A list of tuples, each of which contains (id, name, wins, matches):
        id: the player's unique id (assigned by the database)
        name: the player's full name (as registered)
        wins: the number of matches the player has won
        matches: the number of matches the player has played
    """
    query = 'SELECT * FROM "player_standings"'
    cursor = DB().execute(query)["cursor"]
    standings = cursor.fetchall()
    cursor.close()

    return standings
開發者ID:obelesk411,項目名稱:udacity_tournament_project,代碼行數:22,代碼來源:tournament.py

示例2: swiss_pairings

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import fetchall [as 別名]
def swiss_pairings():
    """
    Returns a list of pairs of players for the next round of a match.

    Assuming that there are an even number of players registered, each player
    appears exactly once in the pairings.  Each player is paired with another
    player with an equal or nearly-equal win record, that is, a player adjacent
    to him or her in the standings.

    Returns:
      A list of tuples, each of which contains (id1, name1, id2, name2)
        id1: the first player's unique id
        name1: the first player's name
        id2: the second player's unique id
        name2: the second player's name
    """

    query = 'SELECT * FROM "swiss_pairings"'
    cursor = DB().execute(query)["cursor"]
    pairings = cursor.fetchall()
    cursor.close()

    return pairings
開發者ID:obelesk411,項目名稱:udacity_tournament_project,代碼行數:25,代碼來源:tournament.py


注:本文中的db.DB.fetchall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。