Ich kann meiner Liste keine Nummer hinzufügen, die ich in einer Textdatei habe und weiß nicht wie.Wie füge ich eine vom Benutzer eingegebene Nummer in meine Textdateiliste ein?
-Code bisher:
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()
Dies ist ein Beispiel eines Schlüssels in der Textdatei. Es gibt etwa 100 in der Datei:
Joe,Bloggs,[email protected],01269 512355, 1, 0, 0, 0,
^
Der Wert, den ich diese Zahl möchte hinzugefügt wird die 0
neben der Nummer ist bereits dort in durch einen Pfeil darunter angezeigt. Die Textdatei heißt wie gezeigt players.txt
.
Eine vollständige Codeantwort wäre hilfreich.
Ich finde, dass dieser Code meine Textdatei löscht. Ich habe versucht, damit herumzutüfteln, aber ohne Erfolg :( – Toby
Vielen Dank für die Hilfe :) Sehr geschätzt – Toby