Recalling data from a text document on python 3 -


i have made script save players names followed scores.

i looking recall data python can sorted table in ui.

im sure simple solution can find how save text document.

    players=int(input("how many payers there? "))      open('playerscores.txt', mode='wt', encoding='utf-8') myfile:         in range (players):             username=input('enter username: ')             score=input('enter score: ')             playerinfo= [username,score, '\n']             myfile.write('\n'.join(playerinfo)) 

there multiple ways 1. reopen playerscores.txt file read data store in buffer sort , write again . 2. while tacking input store in buffer sort them , write on txt file.

players=int(input("how many payers there? ")) open('playerscores.txt', mode='wt', encoding='utf-8') myfile:     playerinfo = []     in range (players):         username=input('enter username: ')         score=input('enter score: ')         playerinfo.append([username,score,'\n'])     playerinfo = sorted(playerinfo, key = lambda x: int(x[1]))     in playerinfo:     myfile.write('\n'.join(i)) 

Comments

Popular posts from this blog

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -