Pregunta

The code does something with a line in a text file (that part works - thanks to your help). But if a condition is not met in that line (if it does not contain the word "Intron" or the word "Exon") it should skip to the next line and repeat the action.

dataFile = open('test.txt', 'r')
wordexon = "Exon"
wornintron = "Intron"
for eachLine in dataFile:
    if wordexon or wordintron in Line:
            tmpStr = ' '
            for char in eachLine:
                tmpStr += char
            s = tmpStr.split()
            print '\t'.join((s[0], s[3], s[4]))
    else next(iter)
¿Fue útil?

Solución

Just remove the

else next(iter)

That will do.

That said, you could have written your code like this:

for eachLine in dataFile:
    if not ((wordexon in Line) or (wordintron in Line)):
        continue
    tmpStr = ' '
    for char in eachLine:
        tmpStr += char
    s = tmpStr.split()
    print '\t'.join((s[0], s[3], s[4]))

Also, your condition is wrong. It will always enter the if as it is.

Otros consejos

  1. Either remove next(iter)

  2. or use continue to make your intent clear.

            s = tmpStr.split()
            print '\t'.join((s[0], s[3], s[4]))
    else:
            continue
    
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top