문제

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