0

I have the following code:

if __name__ == '__main__':
    player_information = get_information()
    print "Goalkeepers top 10:"
    goalkeepers = get_position(player_information, "Goalkeeper")
    for player, points in get_top_players(goalkeepers, 10, 5):
        print goalkeepers[player]["name"], points

    print "\nDefenders top 10:"
    defenders = get_position(player_information, "Defender")
    for player, points in get_top_players(defenders, 10, 5):
        print defenders[player]["name"], points

    print "\nMidfielders top 10:"
    midfielders = get_position(player_information, "Midfielder")
    for player, points in get_top_players(midfielders, 10, 5):
        print midfielders[player]["name"], points

    print "\nForwards top 10:"
    forwards = get_position(player_information, "Forward")
    for player, points in get_top_players(forwards, 10, 5):
        print forwards[player]["name"], points

Output when using Ctrl + B on Sublime Text 3 (I have already selected Python after clicking Ctrl + Shift + B).

Goalkeepers top 10:
de Gea 33
Ryan 23
Schmeichel 23
Lössl 22
Ederson 22
Pope 22
Forster 21
Mignolet 21
Hart 20
Courtois 19

Defenders top 10:
Monreal 32
Jones 32
Azpilicueta 30
Trippier 29
Kolasinac 28
Otamendi 27
Fuchs 24
Bellerín 23
Ward 23
Valencia 23

Midfielders top 10:
Ramsey 30
Coutinho 28
Richarlison 28
Mahrez 27
Fernandinho 27
Eriksen 27
David Silva 26

Forwards top 10:
Kane 44
Abraham 30
Diouf 28
Lacazette 25
Lukaku 25
Morata 24
Murray 22
Rashford 21
Jesus 20
Niasse 20

For some reason the Midfielder bit isn't printing correctly (only printing 7 out of 10 players). However, when running from the file from a terminal it prints completely fine, as seen below:

Goalkeepers top 10:
de Gea 33
Ryan 23
Schmeichel 23
Lössl 22
Ederson 22
Pope 22
Forster 21
Mignolet 21
Hart 20
Courtois 19

Defenders top 10:
Monreal 32
Jones 32
Azpilicueta 30
Trippier 29
Kolasinac 28
Otamendi 27
Fuchs 24
Bellerín 23
Ward 23
Valencia 23

Midfielders top 10:
Sané 53
Sterling 38
De Bruyne 31
Ramsey 30
Coutinho 28
Richarlison 28
Mahrez 27
Fernandinho 27
Eriksen 27
David Silva 26

Forwards top 10:
Kane 44
Abraham 30
Diouf 28
Lacazette 25
Lukaku 25
Morata 24
Murray 22
Rashford 21
Jesus 20
Niasse 20

Just printing the points does result in the Sublime Text 3 output being the same, so I thought maybe it had something to do with the encoding, but that didn't change a thing.

Amos
  • 1,154
  • 1
  • 16
  • 35
  • Try to printout just `Sané` in Sublime and also rerun your program with `print repr(midfielders[player]["name"])`. What is the output? – MaximTitarenko Oct 30 '17 at 16:53
  • @MaximTitarenko If I just print out `Sané` it works fine. Adding `repr` gives this for example: `u'San\xe9' 53` and prints out all 10 midfielders correctly. – Amos Oct 30 '17 at 16:59
  • `print u'San\xe9'` also works fine? – MaximTitarenko Oct 30 '17 at 17:00
  • @MaximTitarenko No, for some reason that causes some other things to not be printed (like "Midfielders top 10:" doesn't get printed if I print that on the line before that). – Amos Oct 30 '17 at 17:01
  • Try to see what your stdoud encoding is: 1) `import sys` 2) `print sys.stdout.encoding` – MaximTitarenko Oct 30 '17 at 17:04
  • @MaximTitarenko It's `utf-8`. – Amos Oct 30 '17 at 17:06
  • Hmm, then I can't help, sorry. Btw, I have a similar problem with Sublime: https://stackoverflow.com/questions/46856584/python-2-7-build-on-sublime-text-3-doesnt-print-the-ufffd-character – MaximTitarenko Oct 30 '17 at 17:08
  • Maybe you can try `print u'San\xe9'.encode('utf-8')` or `print u'San\xe9'.encode('utf-8', errors='ignore')`. If it works in the 2nd case it would be `San` in the output – MaximTitarenko Oct 30 '17 at 17:11
  • 1
    It looks like the Sublime's bug. I have everything the same you described. Here is the crutch which should solve your problem: `print midfielders[player]["name"] + ' ', points` <-- add extra space to midfielders string – MaximTitarenko Oct 30 '17 at 17:32

0 Answers0