i am writing a code in python but it is coming error when i write the
for line in username:
content = username.split(' , ')
content = line.split(",")
NOTE: your split is explicitly expecting <space><comma><space> which is
an unnatural usage of commas. Better, I would think, is to use
content[*].strip() to get rid of the spaces after splitting on the comma.
if content == userName:
content = score
line = content + ', ' + content + '\n'
Confusing usage. Your main input is a list or iterable called
"username", yet you are expecting the first term of each LINE of that
iterable to contain something you compare to whatever userName contains.
Also, note that you are appending a newline when recreating line, but
does the unmodified line end with a newline? (I'm assuming you later write
either the modified or unmodified line to some file).
There is no need to bind "score" to content if the only usage is
then to join strings. Also, "score" needs to be a string for that joining
to work -- if it is numeric you need to convert it. Consider:
for line in username: #still don't like that object name...
#user_scores may be more applicable.
uName = line.split(",").strip() #don't care about rest
if uName == userName:
line = "%s, %s\n" % (uName, score)
#using %s means whatever "score" type, it will
#be converted to a string representation