Mike Shlanta
Mike Shlanta

Reputation: 168

Frustrating python syntax error

I am writing a script to automate HvZ games at my college and have run into this strange frustrating syntax error:

  File "HvZGameMaster.py", line 53
class players(object):
    ^
SyntaxError: invalid syntax

Here is the offending code

class mailMan(object):
    """mailMan manages player interactions such as tags reported via text messages or emails"""
    def __init__(self, playerManager):
        super(mailMan, self).__init__()
        self.mail = imaplib.IMAP4_SSL('imap.gmail.com')
        self.mail.login(args.username,args.password)
        self.mail.list()
        # Out: list of "folders" aka labels in gmail.
        self.mail.select("inbox") #connect to inbox.

    def getBody(self, emailMessage):
        maintype = emailMessage.get_content_maintype()
        if maintype == 'multipart':
            for part in emailMessage.get_payload():
                if part.get_content_maintype() == 'text':
                    return part.get_payload()
        elif maintype == 'text':
            return emailMessage.get_payload()

    def getUnread(self):
        self.mail.select("inbox") # Select inbox or default namespace
        (retcode, messages) = self.mail.search(None, '(UNSEEN)')
        if retcode == 'OK':
            retlist = []
            for num in messages[0].split(' '):
                print 'Processing :', messages
                typ, data = self.mail.fetch(num,'(RFC822)')
                msg = email.message_from_string(data[0][1])
                typ, data = self.mail.store(num,'-FLAGS','\\Seen')
                if retcode == 'OK':
                    for item in str(msg).split('\n'):
                        #finds who sent the message
                        if re.match("From: *",item):
                            print (item[6:], self.getBody(msg))
                            retlist.append((item[6:], self.getBody(msg).rstrip())
                            #print (item, self.getBody(msg).rstrip())


class players(object): #<-the problem happens here
    """manages the player"""
    def __init__(self, pDict):
        super(players, self).__init__()
        self.pDict = pDict
    #makes a partucular player a zombie
    def makeZombie(self, pID):
        self.pDict[pID].zombie = True
    #makes a partucular player a zombie
    def makeHuman(self, pID):
        self.pDict[pID].zombie = False

As far as I can tell what I have written is correct and I have checked to make sure it is all tabs and not spaces I have made sure i don't have any erroneous \r's or \n's floating around (all \n's are where the should be at the end of the line and I'm not using any \r's)

You can find all my code for this project here if you would like to try running it yourself

Upvotes: 0

Views: 706

Answers (1)

unutbu
unutbu

Reputation: 880907

There is an unbalanced (missing) parenthesis on the line above the line raising the error:

retlist.append((item[6:], self.getBody(msg).rstrip())

Note that some editors have matching parenthesis highlighting, and key combinations for moving back and forth across matched parentheses. Using an editor with these features can help cut down on these errors.

Upvotes: 2

Related Questions