title: How can I untokenize a replaced spacy.tokens.token.Token?
body: <p>I was trying to replace the location name from a string and replace it with any city from the list mentioned below, randomly and the get the new formed string and append it to a file. I tried using spacy for this. I can easily detect the cities and replace the token, but I am stuck with appending them to get the new line.</p>
  <pre><code>from pprint import pprint
  import spacy
  import random
  
  list = ['Delhi','Mumbai','Bangalore','Agra','Jaipur','Noida','Lucknow','Bombay','Jaipur','Indore','Chandigarh','Guwahati','Ghaziabad','Faridabad',
          'Pune','Chennai','kolkata','Hyderabad','Goa']
  
  nlp = spacy.load('en_core_web_sm')
  
  sentence = '''Can You deliver pizza to London.'''
  
  entities = nlp(sentence)
  
  pprint([(X, X.ent_iob_, X.ent_type_) for X in entities])
  newstr=&quot;&quot;
  for X in entities:
      newstr += X
      if  X.ent_type_=='GPE' and X.ent_iob_=='B':
          X = random.choice(list)
          print(X)
          #print(type(X))
      elif X.ent_type_=='GPE' and X.ent_iob_=='I':
          X= ' '
  
  
  
  pprint(newstr)
  </code></pre>
  <p>i am getting the following error:</p>
  <pre><code> Traceback (most recent call last):
    File &quot;C:\Users\shahi\PycharmProjects\pythonscrappingproject\main.py&quot;, line 17, in &lt;module&gt;
      newstr += X
  TypeError: can only concatenate str (not &quot;spacy.tokens.token.Token&quot;) to str
  </code></pre>
  <p>When i try to run this with commenting out - newstr += X ; it runs okay.</p>