私はテキストファイルにある私のリストに番号を追加することができません。これまで入力した番号をテキストファイルリストに追加するにはどうすればよいですか?
コード:
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[7] + points
L.close()
これは、テキストファイルのキーのサンプルです。約100は、ファイル内にあります。
Joe,Bloggs,[email protected],01269 512355, 1, 0, 0, 0,
^
私はこの番号が追加されたい値がその下矢印そこではすでに数、ほか0
です。テキストファイルは図のようにplayers.txt
と呼ばれています。
完全なコードの回答が役に立ちます。
このコードは私のテキストファイルを削除します。 Iveはそれを使って周りを試してみたが役に立たなかった:( – Toby
助けをありがとう:)ありがとう – Toby