Question: I keep getting the error when running my code: 

> 
> TypeError: object of type '\_io.TextIOWrapper' has no len() function
> 
> 
> 

How do I get it to open/read the file and run it through the loop?

Here's a link to the file that I am trying to import: 
[download link of the DNA sequence](https://www.dropbox.com/s/4tis7c2853v2tk7/dna.txt?dl=0)

```
    def mostCommonSubstring():
        dna = open("dna.txt", "r")
        mink = 4
        maxk = 9
        count = 0
        check = 0
        answer = ""
        k = mink
        while k <= 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 >= check:
                    answer = sub
                    check = count
            k=k+1
        print(answer)
        print(check)

```

Answer: 
The problem occurs due to the way you are opening the text file.
You should add `dna = dna.read()` to your code.
so your end code should look something like this:

```
def mostCommonSubstring():
    dna = open("dna.txt", "r")
    dna = dna.read()
    mink = 4
    maxk = 9
    count = 0
    check = 0
    answer = ""
    k = mink
    while k <= 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 >= check:
                answer = sub
                check = count
        k=k+1
    print(answer)
    print(check)

```
[@tfabiant](https://twitter.com/tfabiant) : I suggest this script to read and process a DNA sequence. 
To run this code, in the terminal: **python readfasta.py fastafile.fasta**

```
import string, sys
##########I. To Load Fasta File##############
file = open(sys.argv[1]) 
rfile = file.readline()
seqs = {} 
##########II. To Make fasta dictionary####
tnv = ""#temporal name value
while rfile != "":
    if ">" in rfile:
        tnv = string.strip(rfile)
        seqs[tnv] = ""
    else:
        seqs[tnv] += string.strip(rfile)    
    rfile = file.readline()
##############III. To Make Counts########
count_what = ["A", "T", "C", "G", "ATG"]
for s in seqs:
    name = s
    seq = seqs[s]
    print s # to print seq name if you have a multifasta file
    for cw in count_what:
        print cw, seq.count(cw)# to print counts by seq

```