elif giving syntax error python?
Question: I'm trying to parse an XML document and get certain tags. I'd like to grab the
name tag (only if it's the name tag nested within artist) and the title tag
(only if it's the one nested within release).  
That's not too important, though, the important thing is that I'm for some
reason getting an error saying the elif statement is invalid syntax  
I've looked through other posts and made sure that my tabbing is correct and
that there aren't any extra newlines after any of the if's.

This is the code snippet:

    
    
    from lxml import etree
    import sys
    
    #infile = raw_input("Please enter an XML file to parse:  ")
    outfile = open('results.txt', 'a')
    
    path = []
    for event, elem in etree.iterparse('releases7.xml', events=("start", "end")):
        if event == 'start':
            path.append(elem.tag)
        elif event == 'end':
            # process the tag
            if elem.tag == 'name':
                if 'artist' in path and not 'extraartists' in path and not 'track' in path:
                    outfile.write( 'artist = ' + elem.text.encode('utf-8') + '\n' )
            elif elem.tag == 'title':
                if 'release' in path and not 'track' in path:
                    outfile.write( 'release title = ' + elem.text.encode('utf-8') + '\n')
                else:
                    print 'nonrelease'
            path.pop()
    

This is the error:

    
    
    File "DataDestroy_Fast.py", line 18
    elif elem.tag == 'title':
       ^
    SyntaxError: invalid syntax
    

(Note: Using Python2.7 on Mac OSX)


Answer: As I mentioned in a comment, I had an error like this once that was due to a
extra tab character that just happened to be right at a position where it did
nothing visible.

If your editor will let you view invisible characters like tabs and newlines,
you may be able to actually see if that the case. My editor also has an option
to convert tabs to spaces which would fix such a problem. If all else fails,
just delete all the whitespace at the beginning of the line and then carefully
do it over and then see if the error still occurs.

Recently I ran across a really good
[answer](http://stackoverflow.com/a/20308966/355230) to a similar question
[_How can I add a print statement to this code without getting an indentation
error_](http://stackoverflow.com/questions/20308918/how-can-i-add-a-print-
statement-to-this-code-without-getting-an-indentation-erro).

