title: Python write output into a txt file and read from a txt file
body: <p>Hi I am trying to call the write function in a loop(basically, the write() function will be run several times) </p>
  
  <p>What I wrote for the write is something like:</p>
  
  <pre><code>w.write(board+" "+str(number))
  </code></pre>
  
  <p>here board is a string(16 chars) and number is an int. I didn't add in any newline and w is to write to a txt file. </p>
  
  <p>So what I want is the output follows one another with no newline inserted. However, when I output the solution, in the text file, the output will be shifted to a newline. </p>
  
  <p>May I know if there is any inner issue regarding the write() function, is there anyway I could solve it?</p>
  
  <pre><code>def countword(board,dic):
  list=[0]*26
  for char in board:
      if char == '\n':
          break
      list[ord(char)-97]+=1
  number=0
  notFound=False
  for word in range(0,(len(dic)-1)):
      for i in range(26):
          if (list[i]&lt;dic[word][i]):
              notFound=True
              break
      if notFound==True:
          notFound=False
          continue
      number+=1;
  return number
  
  
  
  def dict(dictionary):
  
  result=[]
  s=open(dictionary,'r')
  lines=s.readlines()         
  for line in lines:
      if len(line)&lt;3:
          continue
      list=[0]*26
      line=line.lower()
      for char in line:
          if str(char).isalpha():
              list[ord(char)-97]+=1
      result.append(list)
  s.close()
  return result
  
  f = open('input.txt', 'r')
  w = open('output.txt','w')
  
  
  dic=dict('word_dictionary')
  while True:
      board=f.read(16)
      if len(board)&lt;16:
          print("End of file!")
          break
      print (board)
      number=countword(board,dic)
  
      w.write(board+" "+str(number))
  f.close()
  w.close()
  </code></pre>
  
  <p>In fact, when I read from the file, I also encounter a problem:
  when I read them using simple </p>
  
  <pre><code>board=f.read(16)
  print(board)
  board=f.read(16)
  print(board)  
  </code></pre>