python script error

hi
i am writing a code in python but it is coming error when i write the program :-

for line in username:
content = username.split(’ , ')
if content[0] == userName:
content[1] = score
line = content[0] + ', ’ + content[1] + ‘\n’

it is coming error :
AttributeError: ‘_io.TextIOWrapper’ object has no attribute ‘split’

What version of Python are you using?
How is ‘username’ defined and how is the value being assigned to it?

Cheers,

Jon

hi
i am writing a code in python but it is coming error when i write the
program :-
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[0] == userName:
                               content[1] = score
                               line = content[0] + ', ' + content[1] + '\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[1] 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(",")[0].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