私はテキストファイルにある私のリストに番号を付け加えることができません。これまでテキストファイルからリストの値を編集するのに役立つ必要があります。
コード:
def add_player_points():
# Allows the user to add a points onto the players information.
L = open("players.txt","r+")
name = raw_input("\n\tPlease enter the name of the player whose points you wish to add: ")
for line in L:
s = line.strip()
string = s.split(",")
if name == string[0]:
opponent = raw_input("\n\t Enter the name of the opponent: ")
points = raw_input("\n\t Enter how many points you would like to add?: ")
new_points = string[5] + points
L.close()
これは、テキストファイルのキーのサンプルです。約100は、ファイル内にあります。
Joe,Bloggs,[email protected],01269 512355, 1, 0, 0, 0,
^
私はこの番号が追加されたい値がその下矢印そこではすでに数、ほか0
です。テキストファイルは図のようにplayers.txt
と呼ばれています。
完全なコードの回答が参考になります。
私はあなたがしようとしていることを理解していません。テキストファイルに数値を書きたいですか?または、おそらく、あなたは、テキストファイル内の数字からリストを作成し、リストに数字を追加したいですか? –
私がしたいのは、ユーザーがその値の[5]に数字を入力できるようにすることだけです。その数字がテキストファイルに保存されます。したがって、ユーザーが+5ポイントを追加したい場合。数字が5ポイント上がる – Dave