title: Python: object of type '_io.TextIOWrapper' has no len()
body: <p>I keep getting the error when running my code:  </p>
  
  <blockquote>
    <p>TypeError: object of type '_io.TextIOWrapper' has no len() function</p>
  </blockquote>
  
  <p>How do I get it to open/read the file and run it through the loop?</p>
  
  <p>Here's a link to the file that I am trying to import: 
  <a href="https://www.dropbox.com/s/4tis7c2853v2tk7/dna.txt?dl=0" rel="nofollow noreferrer">download link of the DNA sequence</a></p>
  
  <pre><code>    def mostCommonSubstring():
          dna = open("dna.txt", "r")
          mink = 4
          maxk = 9
          count = 0
          check = 0
          answer = ""
          k = mink
          while k &lt;= maxk:
              for i in range(len(dna)-k+1):
                  sub = dna[i:i+k]
                  count = 0
                  for i in range(len(dna)-k+1):
                      if dna[i:i+k] == sub:
                          count = count + 1
                  if count &gt;= check:
                      answer = sub
                      check = count
              k=k+1
          print(answer)
          print(check)
  </code></pre>