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)
有帮助吗?

解决方案

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.

其他提示

  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
    
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top