elif syntax error [closed]

This is the place for queries that don't fit in any of the other categories.

elif syntax error [closed]

Postby always_stuck » Tue Oct 01, 2013 9:53 am

This may be something really simple (indentation error or missing parenthesis) but I've been debugging it for a couple of days, and I just can't see why I keep getting a syntax error on the following code. Please help before I go crazy.

Code: Select all
with open('EcoDocs TK pdfs.csv', 'rb') as pdf_in:

    """Read-in file register"""
    pdflist = csv.reader(pdf_in, quotechar='"')
    for row in pdflist:
        pathname = "\\\?\\" # Enable long filenames and paths
        check_for_final_directory_backslash()
        check_file_format_present()
        file_exists()

        """Compare filehash"""
        if filehash not in hashes:
            hashes.add(filehash)
            uniques[filehash] = pathname
            EcoDoc[row[1]] = row[0]

        """Else filehash is in hashes"""
        elif filehash in Duplicates:
            #do something


Error:
Code: Select all
  File "c:\Desktop\MyWork\EcoDoc\EcoDoc_duplicate_checker3.py", line 65
    elif filehash in Duplicates:
       ^
SyntaxError: invalid syntax
Last edited by always_stuck on Tue Oct 01, 2013 10:31 am, edited 1 time in total.
always_stuck
 
Posts: 21
Joined: Fri Sep 20, 2013 10:47 am

Re: elif syntax error

Postby Mekire » Tue Oct 01, 2013 10:07 am

Your docstring comments are throwing off the code indentation. Don't use triple quotes for comments mid function. Use them at the top of the function.

-Mek
User avatar
Mekire
 
Posts: 814
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: elif syntax error

Postby always_stuck » Tue Oct 01, 2013 10:31 am

Thanks Mek. I didn't realise they would cause a problem mid-function. Problem fixed.
always_stuck
 
Posts: 21
Joined: Fri Sep 20, 2013 10:47 am

Re: elif syntax error [closed]

Postby ochichinyezaboombwa » Tue Oct 01, 2013 5:08 pm

Despite the topic is closed, I'd like to add:
use comments for comments:

Code: Select all
a = 100
#  a < 5?
if a < 5:
    print "<5"
#  a == 0?
elif a == 0:
    print "==0"
#  else ?..
else:
    print "else"
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests