title: How to fix the " 'str' object does not support item assignment " in python?
body: <p>I was trying to replace the 'X' in a text file with random whole number and rewrite the list to a new file, but it stuck at that line and I'm not sure how to fix it.</p>
  
  <p>I tried to remove the str() but it said it need a str</p>
  
  <pre class="lang-py prettyprint-override"><code>def changex2num(fileName):
      file = open(fileName,'r+')
      table = []
      for line in file:
      #line=line.strip()
          table.append(line)  # add all text in the list
          for num in range(len(line)):
              [num] = line[num].replace('X', str(random.randint(0, 3)))
              table.append(line[num])  # replace x by random integer from the list
  
      writefile = input('which file you would like to write?')
      File = open(writefile,'w')  # open the target file to write
      for things in range(len(table)):
          for ele in range(len(table[things])):
              print(table[things][ele], end=' ')
              File.write(table[things][ele] + '\n')
  
  fileName = input('enter the file you want to read') 
  changex2num(fileName)
  </code></pre>
  
  <p>I expect the X will all be replaced to a number,but it give me an error.</p>