Python3列出打印亚洲字符的问题

时间:2018-02-23 17:39:37

标签: python

我目前在打印亚洲字符期间Tabulate添加奇怪的尾随空格时出现问题,我的代码如下:

def createFormatList():
    n = 10
    lists = [[] for _ in range(n)]

    return lists

def formatMatchOutput(listsFormatter, listPlacement, name, rank, gamesPlayed, rankedWinrate):
    listsFormatter[listPlacement].append(name)
    listsFormatter[listPlacement].append(rank)
    listsFormatter[listPlacement].append(gamesPlayed)
    listsFormatter[listPlacement].append(rankedWinrate)

    return listsFormatter

formatter = list()
            listsFormatter = createFormatList()

            for i in range(0, 5):
                name = str(currentMatchResponse['participants'][i]['summonerName'])
                print(repr(name))
                responseData = requestSummonerData(region, name, APIKey)
                summID = str(responseData['id'])
                responseData2 = requestRankedData(region, summID, APIKey)
                if not responseData2:
                    gamesPlayed = "-"
                    rankedWinrate = "-"
                    rank = "-"
                else:
                    rank = (str(responseData2[0]['tier']) 
                            + " " 
                            + str(responseData2[0]['rank'])
                            + " (" + str(responseData2[0]['leaguePoints'])
                            + "LP)")
                    summW = int(responseData2[0]['wins'])
                    summL = int(responseData2[0]['losses'])
                    gamesPlayed = summW + summL
                    rankedWinrate = calculateWinrate(summW, summL)
                formatter = formatMatchOutput(listsFormatter, i, name, rank, gamesPlayed, rankedWinrate)
            for i in range(5, 10):
                name = str(currentMatchResponse['participants'][i]['summonerName'])
                responseData = requestSummonerData(region, name, APIKey)
                summID = str(responseData['id'])
                responseData2 = requestRankedData(region, summID, APIKey)
                if not responseData2:
                    gamesPlayed = "-"
                    rankedWinrate = "-"
                    rank = "-"
                else:
                    rank = (str(responseData2[0]['tier']) 
                            + " " 
                            + str(responseData2[0]['rank'])
                            + " (" + str(responseData2[0]['leaguePoints'])
                            + "LP)")
                    summW = int(responseData2[0]['wins'])
                    summL = int(responseData2[0]['losses'])
                    gamesPlayed = summW + summL
                    rankedWinrate = calculateWinrate(summW, summL)
                formatter = formatMatchOutput(listsFormatter, i, name, rank, gamesPlayed, rankedWinrate)

            print(colored(tabulate(formatter[0:5], 
                            headers=("{message: <20}".format(message="Summoner Name"), "Rank", 
                            "Games", "Winrate"), tablefmt="orgtbl", numalign="left"), color="blue"))
            print("")
            print(colored(tabulate(formatter[5:10], 
                            headers=("{message: <20}".format(message="Summoner Name"), "Rank", 
                            "Games", "Winrate"), tablefmt="orgtbl", numalign="left"), color="red"))
            print("")

我做了一个打印(repr(name)),除了一个空格外,它在字符后面没有显示任何内容。另外,我看到unicode中的字符后没有空字节。

示例输出:

| Summoner Name          | Rank              | Games   | Winrate   |
|------------------------+-------------------+---------+-----------|
| Takfu                  | MASTER I (198LP)  | 175     | 57%       |
| zhaosf com   007       | MASTER I (34LP)   | 249     | 54%       |
| 뽀허니                    | PLATINUM I (30LP) | 11      | 73%       |
| 마검사데스금성이               | DIAMOND II (39LP) | 82      | 57%       |
| 너의 고추 시들은              | DIAMOND I (0LP)   | 94      | 61%       |

| Summoner Name          | Rank             | Games   | Winrate   |
|------------------------+------------------+---------+-----------|
| 과거 청산                  | DIAMOND I (41LP) | 166     | 54%       |
| Koro1                  | MASTER I (120LP) | 179     | 53%       |
| rvs mid                | MASTER I (180LP) | 226     | 55%       |
| SmartMotive            | MASTER I (71LP)  | 102     | 62%       |
| SmartPilot             | MASTER I (252LP) | 102     | 64%       |

有什么想法吗?

0 个答案:

没有答案